How about this?
$var = exists( $hash{'key'} ) ? $hash{'key'} : "non-existant";
That won't trigger auto-vivification of the hash key. And it accomplishes your goal of reliably returning either the key or something else if the key doesn't exist. Always use exists to check existance of a hash key. defined (or checking for a value) doesn't do what you want.
Dave
In reply to Re: Making a failed hash lookup return something other than undef
by davido
in thread Making a failed hash lookup return something other than undef
by jpfarmer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |