in reply to Hash value test of zero
When a string value gets evaluated numerically, a very simple method is used to convert it to a number: If there is a (decimal) number at the start of the string, that number is read as the numeric value. If there is no number at the start of the string, the numeric value is 0. So "3.14 is pi" == 3.14, but "pi is 3.14" == 0. This check ignores leading whitespace, so " 3" == 3 rather than 0.
Note that this behavior is not specific to hashes, nor even specific to Perl. C's atoi() function behaves the same way (which is where I presume Perl inherited it from) and it may go back even farther than that.
|
|---|