Incrementing an undef value is such a common annoyance that recent releases of perl special-case it. It seems to have been documented somewhere between version 5.004 and 5.8.8. Quoting directly from perlop, which is currently for version 5.10.0,
The auto-increment operator has a little extra builtin magic to it....
undef is always treated as numeric, and in particular is changed to 0 before incrementing (so that a post-increment of an undef value will return 0 rather than undef).
(Update:) Now that I think of it, the conversion to boolean in
is also a special case: undef is being silently converted to false, even when using warnings and strict. If it weren't, you would have to sayif ($countries{$entries[1]}) ...
which would also be fairly annoying.if (defined ($countries{$entries[1]})) ...
In reply to Re^2: Need help on hashes.
by quester
in thread Need help on hashes.
by ElMagnifico
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |