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


in reply to Checking if hash value exists without implicitly defining it

One option is to short circuit the autovivification:

use strict; use warnings; my %Hash; $Hash{44.52}{param1}{key1} = [ 101.01, 'val1' ]; $Hash{95.01}{param2}{key2} = [ 101.02, 'val2' ]; my $neededVal = 80.0; if ( exists $Hash{$neededVal} and exists $Hash{$neededVal}{param1} and exists $Hash{$neededVal}{param1}{key1} ) { print "DEFINED"; } else { for ( keys %Hash ) { print "$_\n"; } }

Output:

95.01 44.52

Update I: Added the needed defined, in case of an earlier (for example) $Hash{$neededVal}{param1}{key1} = 0.

Update II: Replaced defined with exists. Thank you, choroba.