in reply to Best Hash Practices?
so ideally the perlish way of testing a value in a hash might be to do something like this:But the reality is that will not work because an entry for the key automatically gets created in the hash if we try to do that, so we end up having to do something like this insteadif ($myHash{"unknown_if_this_key_exists_yet_or_not"}){...}
No it doesn't. Try it.
The real question is, do you need to test true when $h{key} is set and false? Then you use exists rather than just a boolean test.my %h; if( $h{"isn't there"} ) { 1 } print "$_\n" for keys %h; # does not print anything
UPDATE re-reply: indeed. Well said.
-Paul
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Best Hash Practices?
by almut (Canon) on Oct 09, 2009 at 03:19 UTC |