in reply to Converting Permissionstring to Octal

Well, if you only ever have "r", "w", "x", and "-" present, then you can use pack/unpack for this:

sub perm2mode { my( $perm )= @_; if( 9 != length($perm) || 9 != ( $perm =~ tr/rwx-/1110/ ) ) { die "Unsupported permission string ($_[0])"; } return unpack "v", pack "b*", ''.reverse$perm; }
Use sprintf "0%o" on the return value if you want an octal string, but don't try to use that octal string as a number or you'll get the wrong number:
my $mode= perm2mode("rw-r----x"); my $str= sprintf "0%o", $mode; print "mode=$mode str=$str\n"; my $bad= 0+$str; printf "bad=%d=0%o mode=%d=0%o\n", $bad, $bad, $mode, $mode;
produces:
mode=417 str=0641 bad=641=01201 mode=417=0641
So, for example, using chmod $str, $file; would be wrong just like chmod "0660", $file; is.

        - tye (but my friends call me "Tye")