March 17, 2008

Perl Truth

Filed under: Perl, Programming — morgan @ 23:53

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.

Powered by WordPress