On Thu, 14 Feb 2002 07:57:07 -0900, [EMAIL PROTECTED] (Michael Fowler) wrote:


>I'm tempted to say oct and sprintf's %o are symmetric, meaning they reverse
>each other.  You can think of it that way if it helps, but it might confuse
>you in the case of oct(0500) and sprintf("%o", 0500).

Ok, I have to give it one last try.

#!/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 perms  with file types',"\n";
my $val = sprintf("%o", $mode);
print "$mode in oct is $val\n";
printf "Octal perms are %04o",$mode & 07777;
print ' with file type masked off',"\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 "If octal perms are $oct_perms, then to convert to
decimal perms,",' oct(',$oct_perms,') is ',oct($oct_perms),"\n";
print 'Then if dec perms are ',$perms,' you convert to octal
with sprintf("%o",',$perms,') which is ', sprintf("%o",$perms),"\n";
print 'sprintf("%o",oct($oct_perms)) is ', sprintf("%o",oct($oct_perms)),"\n";
print 'and conversely
oct(sprintf("%o",oct($oct_perms)) is ',oct(sprintf("%o",oct($oct_perms))),"\n";
print 'I\'m a tortured nit-pik but I think I figured out octals :-)',"\n"

                   



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

Reply via email to