Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

PERL chmod inconsistent with the LINUX equivalent

by Anonymous Monk
on Nov 22, 2012 at 09:18 UTC ( #1005083=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello all. I am trying to run chmod (and check for failures), using PERL. The chmod returns 1, but the permissions reported are different than the ones reported after using LINUX's chmod. I have used perl -e to show the inconcictency. See below:

> perl -e '$m= chmod (777 , "run.debug.2.log") ; print "$m\n";' 1 > ls -ltr run.debug.2.log -r----x--x 1 ldagan contract 0 Nov 22 08:59 run.debug.2.log > chmod 777 run.debug.2.log > ls -ltr run.debug.2.log -rwxrwxrwx 1 ldagan contract 0 Nov 22 08:59 run.debug.2.log

As can be seen, chmod 777 in PERL gives permsissions "-r----x--x", which is different than the LINUX equivalent. Any ideas?

Replies are listed 'Best First'.
Re: PERL chmod inconsistent with the LINUX equivalent
by marto (Bishop) on Nov 22, 2012 at 09:28 UTC

    This is clearly explained in the chmod documentation, I suggest reading and understanding it.

      I disagree.

      The problem is that you need a leading zero in order for a number in Perl to be interpreted as octal. That isn't explicitly mentioned in the chmod() documentation, and might not be clear if you don't already know it.

      print 0777 . " (octal)\n"; print 777 . " (decimal)\n";

      When's the last time you used duct tape on a duct? --Larry Wall

        IMHO the chmod documenation is fairly comprehensive.

        "... The first element of the list must be the numeric mode, which should probably be an octal number, and which definitely should not be a string of octal digits: 0644 is okay, but "0644" is not. Returns the number of files successfully changed. See also oct if all you have is a string."

        Note the link to oct, and the fact that the examples clearly show the leading zero. Then follows examples explaining the outcome of several ways of using chmod, including the outcome of using it without the leading zero incorrectly. If you feel this isn't clear enough feel free to contribute to the documentation.

        Update: Strike out mistake.

Re: PERL chmod inconsistent with the LINUX equivalent
by moritz (Cardinal) on Nov 22, 2012 at 09:40 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1005083]
Approved by GrandFather
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2016-09-30 18:41 GMT
Find Nodes?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:

    Results (571 votes). Check out past polls.