08-03-2010
Thanks, pludi. Though that one looks nearly as clumsy. And looking at it makes me fear perl would convert the whole string to an integer array before plucking one character out.
It's surprising that perl can be so remarkably terse in many ways, but clumsy in at least this one.
10 More Discussions You Might Find Interesting
1. Programming
This is actually a c++ question...
Basically I am creating a program that asks for five characters. I have a dictionary file containing tons of words no long than five letters long, on a seperate line. I want to be able to take the five inputted letters and compare them to the words in the file... (3 Replies)
Discussion started by: Phobos
3 Replies
2. UNIX for Dummies Questions & Answers
Hi,
I know, particular value in the variable should always be of lenth 7 , but the value that is present in thevariable might be of any no.of characters less than or equal to 7... if the no.of characters in the variable is less than 7, I want to add, zeroes at the starting of the field.. How can... (3 Replies)
Discussion started by: thanuman
3 Replies
3. Programming
how we can replace char with a string
example
char *a="a.s"
so finally
what i ant to do
raplace a with ant and s sree
so in my array a i want to store the value as "ant.sree"
thank u in advance (1 Reply)
Discussion started by: phani_sree
1 Replies
4. Shell Programming and Scripting
Hi,
Need to extract a string from one file and search the same in other files.
Ex:
I have file1 of hundred lines with no delimiters not even space.
I have 3 more files.
I should get 1 to 10 characters say substring from each line of file1 and search that string in rest of the files and get... (1 Reply)
Discussion started by: mohancrr
1 Replies
5. Shell Programming and Scripting
i have a script that reads a plain text file. (its a ksh, and i can use bash also)
each line of the file is a fullpath of a file. that makes the list huge.
i need to add a functionalitie to that script, i have to be able to add
/usr/* or /usr/ and with that reference all the files and folders... (6 Replies)
Discussion started by: broli
6 Replies
6. Shell Programming and Scripting
I am stumped! I need to parse an input parameter to a script that has the form '-Ort'. I basically need 'O', 'r' and 't', i.e. the individual characters in the string parsed.
Since there are no delimiters, I don't know how awk could do this. Can someone tell how to do this, this should be a... (5 Replies)
Discussion started by: ALTRUNVRSOFLN
5 Replies
7. Shell Programming and Scripting
for example this string: gLZMQp8i
Loop become easy if we add space between each char, How to do it?
or other solutions are welcome. (9 Replies)
Discussion started by: honglus
9 Replies
8. Programming
Hi guys, I am stuck up in a situation. I have a SUN box with certain logs which I need to parse to draw a report using Perl.
Now, when I load the text file using a perl degugger to see how the text looks like when the first line of the log file is read in a variable. below is the snapshot of... (2 Replies)
Discussion started by: Asteroid
2 Replies
9. Shell Programming and Scripting
I have input like this :
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 07-FEB-2012 04:19:45
Copyright (c) 1997, 2009, Oracle. All rights reserved.
Used parameter files:
/t3local_apps/apps/oracle/product/11.2.0/network/admin/sqlnet.ora
Used TNSNAMES adapter to resolve... (3 Replies)
Discussion started by: dnam9917
3 Replies
10. Programming
Hello,
This is my code:
i'd like to like to add getenv("MYLIB") in the first case of my buffer inside of '1' , should i do the cast ? and how please ?
Thank you. (1 Reply)
Discussion started by: chercheur857
1 Replies
LEARN ABOUT DEBIAN
stat::lsmode
lsMode(3pm) User Contributed Perl Documentation lsMode(3pm)
NAME
Stat::lsMode - format file modes like the "ls -l" command does
SYNOPSIS
use Stat::lsMode;
$mode = (stat $file)[2];
$permissions = format_mode($mode);
# $permissions is now something like `drwxr-xr-x'
$permissions = file_mode($file); # Same as above
$permissions = format_perms(0644); # Produces just 'rw-r--r--'
$permissions = format_perms(644); # This generates a warning message:
# mode 644 is very surprising. Perhaps you meant 0644...
Stat::lsMode->novice(0); # Disable warning messages
DESCRIPTION
"Stat::lsMode" generates mode and permission strings that look like the ones generated by the Unix "ls -l" command. For example, a regular
file that is readable by everyone and writable only by its owner has the mode string "-rw-r--r--". "Stat::lsMode" will either examine the
file and produce the right mode string for you, or you can pass it the mode that you get back from Perl's "stat" call.
"format_mode"
Given a mode number (such as the third element of the list returned by "stat"), return the appopriate ten-character mode string as it would
have been generated by "ls -l". For example, consider a directory that is readable and searchable by everyone, and also writable by its
owner. Such a directory will have mode 040755. When passed this value, "format_mode" will return the string "drwxr-xr-x".
If "format_mode" is passed a permission number like 0755, it will return a nine-character string insted, with no leading character to say
what the file type is. For example, "format_mode(0755)" will return just "rwxr-xr-x", without the leading "d".
"file_mode"
Given a filename, do "lstat" on the file to determine the mode, and return the mode, formatted as above.
Novice Operation Mode
A common mistake when dealing with permission modes is to use 644 where you meant to use 0644. Every permission has a numeric
representation, but the representation only makes sense when you write the number in octal. The decimal number 644 corresponds to a
permission setting, but not the one you think. If you write it in octal you get 01204, which corresponds to the unlikely permissions
"-w----r-T", not to "rw-r--r--".
The appearance of the bizarre permission "-w----r-T" in a program is almost a sure sign that someone used 644 when they meant to use 0644.
By default, this module will detect the use of such unlikely permissions and issue a warning if you try to format them. To disable these
warnings, use
Stat::lsMode->novice(0); # disable novice mode
Stat::lsMode->novice(1); # enable novice mode again
The surprising permissions that are diagnosed by this mode are:
111 => --xr-xrwx
400 => rw--w----
440 => rw-rwx---
444 => rw-rwxr--
551 => ---r--rwt
600 => --x-wx--T
640 => -w------T
644 => -w----r-T
660 => -w--w-r-T
664 => -w--wx--T
666 => -w--wx-wT
700 => -w-rwxr-T
711 => -wx---rwt
750 => -wxr-xrwT
751 => -wxr-xrwt
751 => -wxr-xrwt
755 => -wxrw--wt
770 => r------wT
771 => r------wt
775 => r-----rwt
777 => r----x--t
Of these, only 400 is remotely plausible.
BUGS
As far as I know, the precise definition of the mode bits is portable between varieties of Unix. The module should, however, examine
"stat.h" or use some other method to find out if there are any local variations, because Unix being Unix, someone somewhere probably does
it differently.
Maybe it "file_mode" should have an option that says that if the file is a symlink, to format the mode of the pointed to file instead of
the mode of the link itself, the way "ls -Ll" does.
SEE ALSO
o "http://www.plover.com/~mjd/perl/lsMode/".
o ls
o chmod
o stat
AUTHOR
Mark-Jason Dominus ("mjd-perl-lsmode@plover.com").
perl v5.10.1 1998-04-20 lsMode(3pm)