in reply to stat question
This is precedence, yes, but also context. With '||', the right hand side of the (list) assignment is a (list of a single) scalar. stat() performed in scalar context, if it succeeds, is a scalar; if it does not succeed, print will return a scalar. Either way, only $dev is ever set.
When you use 'or', the list assignment is performed before the 'or', and the right hand side of the assignment is stat(), evaluated in list context — which is probably what you want.
If stat() fails in list context, it returns the empty list, and so the list assignment evaluates to 0 in the scalar (boolean) context imposed by 'or' — and so print is called on failure, contrary to your statement that it will "never print". (At least here it prints when $file does not exist.)
BTW, you stat $file,
but print $filename. I would hope that
$file is a reference to a file handle :-)
Perhaps more relevant, I notice that $!
was not set when I tried to stat a closed filehandle,
though the stat failed. Funny.
The Sidhekin
print "Just another Perl ${\(trickster and hacker)},"
|
|---|