access mode int->string

V

vertigo

Hello
I have file acces mode as number for example: 755,
and i want to change it to text for example: -rwx------
Is there any module/function for that ?

Thanx
 
G

Gunnar Hjalmarsson

vertigo said:
I have file acces mode as number for example: 755,
and i want to change it to text for example: -rwx------
Is there any module/function for that ?

I have no idea. Why don't you write your own function?
 
J

Jason Hooper

vertigo said:
Hello
I have file acces mode as number for example: 755,
and i want to change it to text for example: -rwx------
Is there any module/function for that ?

There probably is no module for this, but it's relatively
straightforward to create your own, if you break down the
problem into smaller problems. Take one digit at a time
from left to right and use a bitwise AND to test which
bits make up each number, 4 for r, 2 for w, and 1 for x.
Use the simple string concatenation operator (a period: .
) to build the string up.

If I am not mistaken.

- Jason
 
J

Joe Smith

vertigo said:
I have file acces mode as number for example: 755,
and i want to change it to text for example: -rwx------
Is there any module/function for that ?

1) Post to comp.lang.perl.misc instead of this comp.lang.perl newsgroup.
2) Look at 'find2perl' for hints.

unix% find2perl . -ls >temp.pl
my @rwx = qw(--- --x -w- -wx r-- r-x rw- rwx);
my $perms = $rwx[$mode & 7];
$mode >>= 3;
$perms = $rwx[$mode & 7] . $perms;
$mode >>= 3;
$perms = $rwx[$mode & 7] . $perms;
substr($perms, 2, 1) =~ tr/-x/Ss/ if -u _;
substr($perms, 5, 1) =~ tr/-x/Ss/ if -g _;
substr($perms, 8, 1) =~ tr/-x/Tt/ if -k _;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top