more useful options | |
PerlMonks |
Re: Testing for group or world writable filesby kcott (Archbishop) |
on Jul 07, 2015 at 13:48 UTC ( [id://1133541]=note: print w/replies, xml ) | Need Help?? |
G'day Neil, I see answers identifying a precedence problem. Rather than using the ! operator and adding (multiple levels of) parentheses, you can just use the low-precedence equivalent: not (see "perlop: Operator Precedence and Associativity"). There's also low-precedence and, or and xor. I find these operators make the code easier to read than using parentheses: you, of course, may have a different preference. Instead of using Test::More's ok() function (and, where necessary, negating the test), consider using the is() and isnt() functions. This (at least in the case of your posted code) circumvents the precedence issue entirely; it also aligns the test function with the test description. Here's an example roughly based on your code:
[Note that I've used the core (builtin) stat function. File::stat, by default, overrides this.] Output:
Update: While my intent was to compare ok() with is() and isnt(), which I believed I achieved, I did notice a bug in the example code. I've fixed the code; retested; and posted the new code and output. The offending line was:
Update 2: My bug fix (from the initial update) left the code a bit messy. I've tidied that up. Now just one call to stat with the result stored in $mode. Retested successfully; output unchanged; new code posted. -- Ken
In Section
Seekers of Perl Wisdom
|
|