I sometimes access a hash like this:
if(exists $ids{$name}){
$id = $ids{$name};
}
Is that good practice? I’m a bit concerned that it contains two lookups where really one should be done. Is there a better way to check the existence and assign the value?
By checking with
exists, you prevent autovivification. See Autovivification : What is it and why do I care?.UPDATE: As trendels points out below, autovivification does not come into play in the example you posted. I am assuming that the actual code involves multi-level hashes.
Here is an illustration: