Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > access mode int->string

Reply
Thread Tools

access mode int->string

 
 
vertigo
Guest
Posts: n/a
 
      07-05-2004
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

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      07-05-2004
vertigo wrote:
> 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?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Jason Hooper
Guest
Posts: n/a
 
      07-05-2004
vertigo wrote:
> 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
 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      07-05-2004
vertigo wrote:

> 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 _;
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mmm-mode, python-mode and doctest-mode? Edward Loper Python 0 08-09-2007 05:40 AM
re: mmm-mode, python-mode and doctest-mode? John J Lee Python 0 08-07-2007 07:49 PM
re: mmm-mode, python-mode and doctest-mode? Edward Loper Python 0 08-07-2007 08:58 AM
mmm-mode, python-mode and doctest-mode? John J Lee Python 3 12-01-2005 08:35 PM
Safe Mode (?) - It is meant to be normal mode but looks like safe mode English Patient Computer Support 3 10-03-2004 11:10 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57