http://www.perlmonks.org?node_id=339261


in reply to Testing for Truth

An array in boolean context is assumed to mean "are there any elements in me" and represents true because it contains 0. Since undefined values, the string "", and 0 (also "0") are false, the 0th element in the array is false.

(defined $foo->[0]) ? print "TRUE\n" : print "FALSE\n";

Should print TRUE. Note that you should use:

use strict; use warnings;

at the top of all your scripts to alert you to things like this in your code. Of course, in this particular instance, there would be no warnings because what you did is supposed to be widely known.


Want to support the EFF and FSF by buying cool stuff? Click here.