But when you want to make the permissions variable, you need to oct it. Can anyone explain why?
The best explanation is in the documentation (perlfunc, in this case), which says, in part
The first element of the list must be the numerical mode, which should probably be an octal number, and which definitely should not a string of octal digits: 0644 is okay, '0644' is not.
It's the bit pattern behind the number that is significant. Octal is used by convention, because the bits that chmod() cares about when specifying file protection are in three groups of three* -- a natural fit for octal. You could just as well specify them in hex or in decimal, though doing so obscures the intent of the operation.
chmod 0777, $file;
chmod 0x1FF, $file;
chmod 511, $file;
are equivalent.
*Additional bits are used for non-protection stuff like setuid, but it's the 9 low-order protection bits that people usually care about.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.