> Hello group: > > In attempting to set $file2 to the same mode as $file1 I do this: > > my $mode = (stat($file1))[2]; > chmod $mode, $file2; > > That code does the trick but I just want to make sure of: > > 1) > I see in perldoc -f chmod it talks about oct() but if I'm using stat's > mode it should be safe not to use oct() correct? > > 2) $mode is really strange, ls -l shows a file as being 644 but $mode is > 33188 or a directory as 755 but $mode is 16877 >
33188 is 0100644 16877 is 040755 from perldoc -f stat: Because the mode contains both the file type and its permissions, you should mask off the file type portion and (s)printf using a "%o" if you want to see the real permissions. Since chmod() cannot not change the *type* of the file, those bits appear to be ignored. ..........................BEGIN PERL PROGRAM ........................... #!/usr/bin/perl use strict; use warnings; my $file = '/tmp/test.pl'; my $mode = (stat($file))[2]; print "Mode was; $mode or in octal (which makes more sense) ", sprintf("%o", $mode),"\n" ; ........................... END PERL PROGRAM ........................... -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Lawrence Statton - [EMAIL PROTECTED] s/aba/c/g Computer software consists of only two components: ones and zeros, in roughly equal proportions. All that is required is to sort them into the correct order. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>