On Wed, 13 Feb 2002 15:14:39 -0900, [EMAIL PROTECTED] (Michael Fowler) wrote:

>You have it backwards.  Octal 100500 is 33088 in decimal.  You just did the
>conversion with the oct operator.
>
>You're confused about what oct does; it returns the decimal representation
>of an octal value.  Also, Perl is going to trip you up here; the decimal

After putting on the dunce cap and typing 100 times:
"the oct function takes a decimal value and returns octal,
 and  (stat file)[2] returns a decimal value" I finally see it.
I think I do anyways. :-)

#!/usr/bin/perl
use strict;
use warnings;
#usage testmode file, file defaults to self
my $open = shift || $0;
my $mode = (stat $open)[2];
print '(stat(file))[2] is ',$mode,' which is decimal representation of the octal
value with file types',"\n";
printf "Permissions are %04o",$mode & 07777;
print ' with file type masked off',"\n";
my $val = sprintf("%o", $mode);
print "$mode in oct is $val\n";

my $perms = (stat("$open"))[2] & 07777;
my $oct_perms = sprintf "%lo", $perms;
print 'decimal perms are ',$perms,' with file type masked off',"\n";
print 'octal_perms are ',"$oct_perms",' with file type masked off',"\n";

print 'oct(',$perms,') ','is ',sprintf("%o",$perms),"\n";
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to