Problems? Is your data what you think it is? | |
PerlMonks |
Re^2: POSIX::S_ISDIR() with $stat->mode values from Windows vs. Linuxby jakobi (Pilgrim) |
on Oct 05, 2009 at 19:31 UTC ( [id://799327]=note: print w/replies, xml ) | Need Help?? |
Ok, I'll bite First of all, I don't see any need for oct(). This is a bitfield - so you might want to do a perl -e 'printf "0%o\n", 16895' for human consumption. And if you ever see that on Unix and it isn't called tmp, you'll probably also want to give the culprit a lecture about security risks. The readable form of this number is 040777, with 777 being the permission bits of read/write/executable for all of user, group and other (read maybe as 040ugo:) ). Now let's peek at the includes, pretending that the 040 wasn't an obvious hint to us for the encoding of the directory file type. Might be a useful trick of the trade for use with more difficult future questions in situations where Perl offers less or no suitable abstractions or you need some background to properly make use of them.
The numbers above are octal numbers, for improved readability, as hinted at by the leading 0. So you say in Perl $mode & 0777 to restrict the $mode to the actual file permissions (cf. chmod arguments!). Say $mode & 07 to check the access of nobody (but remember in the background that there's also filesystem specific stuff like ACL and Extended Attributes, which can modify the traditional perms; hopefully somebody alreade made a module for checking on these headaches :)) To test for a directory w/o POSIX, but just boolean operators directly. Which is just what the minimal wrapping by the POSIX module does: warn "a dir\n" if (stat ".")[2] & 040000 == 040000with 040000 being __S_IFDIR from the includes above. Recognized POSIX::S_IFDIR? I think that should be enough about background and boolean masking. Note that instead of and, or, exor you can also left or right-shift the bits (man perlop: search for &, |, ^, <<, >>). AFAIS, the missing bits / misunderstandings were:
If possible however, try the normal perl tests like -d as already suggested. cu
In Section
Seekers of Perl Wisdom
|
|