This is "autovivification" and was just discussed the other day, see the replies in the thread Array dereference in foreach(), including the ones deeper down in the thread.
Use exists to check if a hash key exists. As described in its documentation, if you have multi-level data structures (hashes of hashes), you need to check every level. Update: Discipulus just updated to show an example.
In reply to Re: keys %{$hash->{$href}} adds $href to the hash if it doesnt exist?
by haukex
in thread keys %{$hash->{$href}} adds $href to the hash if it doesnt exist?
by nikmit
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |