http://www.perlmonks.org?node_id=11153574


in reply to Hash value test of zero

Firstly, note that this is not limited to hash values.
You'll get the same thing if you simply do $foo = 'a string'; and then test $foo == 0, etc.

The == operator compares both sides in numeric context.
For your first test, the string 'a string' evaluates to 0 in numeric context and therefore the numeric equivalence holds. (Note that the empty string"", assigned in a later test, also evaluates to 0 in numeric context.)

With the examples you've provided, you'll get the results you're after by simply replacing == with eq throughout, as that will instead compare both sides as strings (ie in string context).

Cheers,
Rob