I'm going to eschew the unpack or pack functions in my reply. Here is one way to accomplish what you are after. There are more elegant ways I'm sure.
#!/usr/bin/perl ################################################################# $|=1; use strict; my $permstring="rw-rw----"; my $num=0; for (my $i=0;$i<9;$i+=3) { $num = ($num * 8) + getoctal(substr($permstring,$i,3)); } printf "%o\n",$num; exit(0); sub getoctal { my $str=shift; my $rval=0; $rval+=4 if substr($str,0,1) ne '-'; $rval+=2 if substr($str,1,1) ne '-'; $rval+=1 if substr($str,2,1) ne '-'; return $rval; } ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Peter L. Berghold --- Peter@Berghold.Net "Those who fail to learn from history are condemned to repeat it."
In reply to Re: Converting Permissionstring to Octal
by blue_cowdawg
in thread Converting Permissionstring to Octal
by stefan k
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |