Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^2: PERL chmod inconsistent with the LINUX equivalent

by ColonelPanic (Friar)
on Nov 22, 2012 at 10:12 UTC ( #1005097=note: print w/replies, xml ) Need Help??

in reply to Re: PERL chmod inconsistent with the LINUX equivalent
in thread PERL chmod inconsistent with the LINUX equivalent

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

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

    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.

      Maybe I should have stated that a little less strongly. I don't have a problem with the chmod documentation as such. I just don't think "read the documentation" is the best answer when the documentation doesn't explicitly address the mistake the OP made. The significance of the leading zero might not be clear to someone who doesn't already know what it means.

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

        The point OP made is that perls chmod does not work the same as chmod on their linux system. The linux chmod command assumes that missing digits are leading zeros, perls chmod does not operate in the same manner. The docuemtnation I suggested reading (and understanding) provides examples and an explanation that the number passed should be an octal number. Perhaps to fully understand this I should also have suggested that OP read man chmod to understand why it works the way it does. The docs also point to portability issues on certain platforms.

        IMHO reading the documentation for each command provedes sufficent information to explain why they behave differently.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1005097]
[LanX]: qwiud you sthink so?
[LanX]: zxwqbd good idea! :)
LanX embraces his new habit spqopiwjdnq
[ambrus]: qQUkZTmHTuKxStGT- BzTIK9gdudif7TkTLI t3mnF144UaAZjkknXY 8nN-QM19wHBsTrp5vB lEYU_Kksa7X1RIBB4x EWLD5X7SW3jGX5ryfN OMn_yL5FTdQxzjhtyX mKN9sjUCzBNHK5Rrp0 S2WMUvIb1i9aZFgjtq VR0GH1bjPMvm1G16iz hBqc1U6toPd4FbJOFj VsOeT745AN1_pO88rD SRAYKtBZwCZedESZmN mvutrOTHiSNwflB- pRfn_k
[Eily]: so far it seems to work
Your Mother reminds the monks they should be grateful not to share an office, lest they be subjugated to constant inanities like, "Czech please!"
[LanX]: what's strange is that the "Cowboy you said this already" message is missing #dqiwd
[LanX]: YM: BTW learn to mute your humanity
[Your Mother]: Cumin? Now I want tacos...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (14)
As of 2017-03-27 16:55 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (320 votes). Check out past polls.