http://www.perlmonks.org?node_id=451869


in reply to Re^2: Heisenberg Uncertainty Hash
in thread Heisenberg Uncertainty Hash

Putting an exists there, (exists $hash{'d'}->{'value'}) still autovivificates $hash{'d'}. This might be surprising, but it is logical. After all, you are enquiring about the hash %{$hash{'d'}} (asking whether it contains the key 'd'). Since that hash doesn't exists yet, Perl does what it always does in that case: it creates it.

If you want to cover all your bases, and make sure no hash gets created as a side effect, be more explicite:

if (exists $hash{'d'} && ref $hash{'d'} eq "HASH" && exists $hash{ +'d'}->{value}) { ... }