What is Truth?
- Any string is true except for "" and "0".
- Any number is true except for 0.
- Any reference is true.
- Any undefined value is false (implictly by first rule).
Truth is evaluated in a scalar context.
What is the truth of a list?
There is no perl opeartion that will return a list
in a scalar context, they all return a scalar value instead.
|
Examples:
0 | # would become the string "0", so false |
1 | # would become the string "1", so true |
10 - 10 | # 10-10 is 0, becomes the string "0", so false |
0.00 | # becomes 0, converts to string "0", so false |
"0" | # the string "0", so false |
"" | # the null string, so false |
"0.00" | # the string "0.00", neither empty nor exactly "0", so true |
"0.00" + 0 | # the number 0 (coerced by the +), so false |
\$a | # a reference to $a, so true, even if $a is false |
undef() | # a function returning the undefined value, so false |
|