access mode int->string

Discussion in 'Perl' started by vertigo, Jul 5, 2004.

  1. vertigo

    vertigo Guest

    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
    vertigo, Jul 5, 2004
    #1
    1. Advertising

  2. 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
    Gunnar Hjalmarsson, Jul 5, 2004
    #2
    1. Advertising

  3. vertigo

    Jason Hooper Guest

    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
    Jason Hooper, Jul 5, 2004
    #3
  4. vertigo

    Joe Smith Guest

    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 _;
    Joe Smith, Jul 5, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Schnoffos
    Replies:
    2
    Views:
    1,210
    Martien Verbruggen
    Jun 27, 2003
  2. Hal Styli
    Replies:
    14
    Views:
    1,632
    Old Wolf
    Jan 20, 2004
  3. John J Lee
    Replies:
    3
    Views:
    473
    bruno at modulix
    Dec 1, 2005
  4. Edward Loper
    Replies:
    0
    Views:
    460
    Edward Loper
    Aug 7, 2007
  5. John J Lee
    Replies:
    0
    Views:
    514
    John J Lee
    Aug 7, 2007
Loading...

Share This Page