in reply to 'ls' with octal permissions

my %d = map {split//} qw/sx S- r4 w2 x1 -0/;

Really???    Why not just:

my %d = qw/s x S - r 4 w 2 x 1 - 0/;


Or you could just do the whole thing like this:

for my $file ( @ARGV ) { my $mode = ( stat $file )[ 2 ]; my $ls = `/bin/ls -l $file`; $ls =~ s/^(.)([rwxsStT-]+)(?=\s)/[$1] @{[ sprintf '%04o ', $mo +de & 07777 ]}/; print $ls; }

Replies are listed 'Best First'.
Re^2: 'ls' with octal permissions
by oko1 (Deacon) on Mar 27, 2011 at 14:35 UTC

    > Why not just [...]

    Because TMTOWTDI. :) Not a lot of cost to it, so no real difference. Besides I like the visual pairing of the sets.

    On the other hand, your suggested solution invokes 'ls' and 'stat' for every single file, and takes away the ability to use all the other 'ls' options (at which point it would be easier to use a shell script.) That's exactly what I wanted to avoid. I actually use this as a sort of a 'wrapper' around 'ls' - a drop-in replacement - in which I use the '-O' switch (which I shift off) to enable this behavior; otherwise, I just pass everything to 'ls'.

    -- 
    Education is not the filling of a pail, but the lighting of a fire.
     -- W. B. Yeats