Subject: | Failure to open file named 0 due to precedence of || vs or |
Date: | Tue, 18 Nov 2008 10:54:58 -0500 |
To: | bug-File-MimeInfo [...] rt.cpan.org |
From: | J Chapman Flack <jflack [...] math.purdue.edu> |
A user has reported errors like
Can't use an undefined value as a symbol reference at
.../lib/File/MimeInfo/Magic.pm line 55.
when trying to classify a file named "0".
The problem turns out to be the idiom:
open $fh, '<', $file || return undef;
which, to be correct, needs the operator 'or' instead of ||:
open $fh, '<', $file or return undef;
The two operators have different precedence: the version
with || is equivalent to
open $fh, '<', ( $file || return undef );
which of course causes undef to be returned if $file is the
empty string or "0".
Credit to Dan Trinkle for spotting that operator precedence was
the problem.
There are two lines in Magic.pm and four in MimeInfo.pm to
be corrected.
Reported for 0.14.
Chapman Flack
mathematics
Purdue