Every time I write a perl script I have to pause to remember how Perl handles true and false. It seems Nathan Torkington answered the question years ago in this article from the Perl Journal. Truth is relatively simple when put in his terms:
– only scalars can be true/false (ie no lists)
– undef is false
– “” is false
– 0 is false
– 0.0 is false
– “0” is false
– all else is true
This means negative numbers are true.
I don’t think that the first statement is true. An empty list is false, e.g.:
my @a = ();
unless (@a) {
print “list is empty\n”;
}
In a scalar context, the value of @a is the number of elements.