We don't bite newbies here... much | |
PerlMonks |
bitwise AND against a variable containing Fnctl constants not returning desired resultsby theillien1 (Acolyte) |
on Jun 05, 2014 at 22:15 UTC ( [id://1088934]=perlquestion: print w/replies, xml ) | Need Help?? |
theillien1 has asked for the wisdom of the Perl Monks concerning the following question: I wrote a script which will scan local, mounted file systems for world-writable files excluding any which are in a hash generated from a list in a file. It utilizes Fcntl in order to make use of the file mode constants. The current version runs stat three times against a file:
This is, of course, less than ideal since it is running one operation three times against every file. That said, it works and the output contains only the files I'm looking for minus those I've explicitly excluded. It was suggested that I instead set a variable which contains these constants and run a bitwise AND with the $mode field from stat(). I tried this. The result was that the script returned every file, even those not world-writable. Additionally, I get a "Possible precedence problem" error. I'm inexperienced with bitwise operations so I don't know what I'm encountering with that particular error.
Undestandably, the context is extremely vague here. I'm not sure if etiquette allows for the posting of entire scripts so I've pastebin'ed it: http://pastebin.com/A8d3K2mR EDIT: All answers pointed to using parens around the bitwise AND before comparing to $mask. This solved both the "Possible precedence" error as well as the results being unexpected.
Back to
Seekers of Perl Wisdom
|
|