Or, for a less verbose version that doesn't require taint mode, 5.10, or a shouty license (consider it public domain):
use Fcntl ':mode'; my %TYPE = (S_IFDIR,'d',S_IFCHR,'c',S_IFBLK,'b',S_IFREG,'-',S_IFLNK,'l +', S_IFSOCK,'s'); sub o { my ($mode, $xr, $xid) = @_; (($mode & ($xr | $xid)) == ($xr | $xid)) ? 's' : ($mode & $xr) ? 'x' : ($mode & $xid) ? 'S' : '-'; } sub strmode { my ($mode) = @_; ($TYPE{$mode & S_IFMT} || '?') . (($mode & S_IRUSR) ? 'r' : '-') . (($mode & S_IWUSR) ? 'w' : '-') . o($mode, S_IXUSR, S_ISUID) . (($mode & S_IRGRP) ? 'r' : '-') . (($mode & S_IWGRP) ? 'w' : '-') . o($mode, S_IXGRP, S_ISGID) . (($mode & S_IROTH) ? 'r' : '-') . (($mode & S_IWOTH) ? 'w' : '-') . o($mode, S_IXOTH, S_ISVTX) }
EDIT: Actually, this problem makes a decent golf hole. Given some files in @ARGV, print "modestring file\n" for each file. Here's a start (283 262 222 203 strokes w/o newlines):
#!/usr/bin/perl -l sub i{'-'} sub o{$m&$_[0]?$m&$_[1]?'s':x:$m&$_[1]?S:i} print qw(? c d b - l s)[($m=(lstat)[2])>>13] ,$m&256?r:i ,$m&128?w:i ,o(64,2048) ,$m&32?r:i ,$m&16?w:i ,o(8,1024) ,$m&4?r:i ,$m&2?w:i ,o(1,512) ," $_"for@ARGV;
EDIT: Or, with bitwise goodness, 131 127:
#!/usr/bin/perl -l for$f(@ARGV){ $_=sprintf"%9b",($m=(lstat$f)[2])&511; y/01/\0\xff/; $_&=rwxrwxrwx; y/\0/-/; print qw(? c d b - l s)[$m>>13],"$_ $f" }

In reply to Re: strmode in Perl (convert octal permissions to symbolic) by educated_foo
in thread strmode in Perl (convert octal permissions to symbolic) by afresh1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.