Contributed by arturo
on Sep 25, 2000 at 23:04 UTC
Q&A
> files
Description: I want to take $file1 and give it the same permissions as $file2, which may be owned by another user. Perl's stat() function returns the mode, but it's not obvious how to get from the 5-digit decimal number returned to octal values (executing oct($mode) on it doesn't give a sensible value). So, how do you do the conversion?
Answer: How do I get all the permission flags on a file? contributed by merlyn You don't need octal, ever. You need a number. That number from stat can be handed over directly. For safety, you may want to bit-and it with 07777, but I don't think there'll be any
nonsense anyway. | Answer: How do I get all the permission flags on a file? contributed by BastardOperator If merlyn's answer confuses you at all, try this:
sub return_mode {
my $mode = shift;
my @modelist = (($mode & 7000)>>9, ($mode & 0700)>>6, ($mode & 007
+0)>>3, ($mode &0007));
return join('', @modelist);
}
Also, I don't know if you would be concerned with ACL's at all, I'm not sure how you would handle those if you were, just wanted to give you a heads up depending on how detailed you're being. |
Please (register and) log in if you wish to add an answer
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
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.
|
|