Sunday, January 2, 2011

Perl: if, while and unless condition true rules

There are many Perl functions which test for Truth. Some are if, while, unless . So it is important you know what truth is, as defined by Perl, not your tax forms. There are three main rules:
  1. Any string is true except for "" and "0".
  2. Any number is true except for 0. This includes negative numbers.
  3. Any undefined variable is false. A undefined variable is one which doesn't have a value, ie has not been assigned to.

No comments: