The example given by
draconis only provides the "owner/group/other" mode flags for the file in question. It looks like the OP was asking how to learn what sort of access is available to the person running the perl script.
In order to do that, you would need to combine the mode field from stat with knowledge of the current user's group membership(s) and whether the current user happens to be the owner of the file, so you'll know which set of bits from the mode flag are relevant for determining file access.
A better way for the task at hand would be:
($r,$w,$x) = (-r $path, -w _, -x _);
print "Access: read $r, write $w, execute (search dir) $x\n";
A few notes:
- using underscore as the argument for "-w" and "-x" tells perl to use the same "stat" data obtained by "-r"
- as written above, any permission not granted will be "undef", so the printed message in this case would look like "read 1, write , execute (search dir) 1" when there is no write permission
- contrary to derby's comment, "execute" permission on a directory does not control whether or not you can "cd" into that directory; it does determine whether you can "search" the directory contents -- i.e. you need execute permission to run "ls" with no args, or "find", or do any sort of operation using "*" or "?" as part of a file name within the directory.
- 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.