Converts UNIX file permissions to absolute mode. ( ie. rwsrwxrwx -> 4777 ). This is useful when you don't have the file locally .. just the output of the listing of the file. (Ex: Using Expect to access a remote system and obtaining data via shell commands )
#!/usr/local/bin/perl $a = <>; chomp( $a ); @p0{"-","r"} = ( 0, 400 ); @p1{"-","w"} = ( 0, 200 ); @p2{"-","x","s","S"} = ( 0, 100, 4100, 4000 ); @p3{"-","r"} = ( 0, 40 ); @p4{"-","w"} = ( 0, 20 ); @p5{"-","x","s","l"} = ( 0, 10, 2010, 2000 ); @p6{"-","r"} = ( 0, 4 ); @p7{"-","w"} = ( 0, 2 ); @p8{"-","x","t","T"} = ( 0, 1, 1001, 1000 ); @a = (\%p0,\%p1,\%p2,\%p3,\%p4,\%p5,\%p6,\%p7,\%p8); $perms = 0; $result = `ls -lLd $a | awk '{print \$1}' | cut -b2-10`; chomp( $result ); print "$result\n"; for ( $x = 0; $x <= 8; $x++ ) { $b = substr( $result, $x, 1 ); print "char -> $b position -> $x "; print "value -> $a[$x]{substr( $result, $x, 1 )}\n"; $perms = $perms + $a[$x]{substr( $result, $x, 1 )}; } print "perms -> $perms\n";

In reply to File permission converter by Centaurus

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.