Works for strings too: $x ||= '': will avoid warnings about using an undefined value in a print, string concatenation, string comparison, regular expression, and so on.
That also turns '0' into '' and so would probably be better written as:
$x= '' if ! defined $x;
Or you can use //= if you are on the bleading edge and eschew backward compatability. Note that ||= is probably the best choice for the numeric case as treating '' as a number can also cause a warning.
- tye
In reply to Re^2: Or, Or, Equals Zero, $x ||= 0 ('')
by tye
in thread Or, Or, Equals Zero, $x ||= 0
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |