in reply to Making a failed hash lookup return something other than undef
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Making a failed hash lookup return something other than undef
by thelenm (Vicar) on Nov 13, 2003 at 20:09 UTC | |
by shenme (Priest) on Nov 13, 2003 at 20:33 UTC |