by kbenson · 11y ago · 0 comments
use Data::Dumper;
my %h;
if ( $h{foo}{bar}{baz} ) { say "Never happens"; }
say Dumper \%h;
And you get this: $VAR1 = {
'foo' => {
'bar' => {}
}
}; my %hash = ();
if (exists $hash{foo}) {print "This doesn't run!";}Your example doesn't cause autovivification even without exists. Autovivification is the automatic creation of the underlying hashes and arrays in a multiple level data structure when they are used while accessing a nested data-structure.
For example, given an empty hash %hash, $hash{foo} does not cause autovivification, but $hash{foo}{bar} will automatically create an empty hash and assign a reference to it to $hash{foo}.
my %h;
dd %h
if %h<foo><bar><baz> { say "Never happens" }
dd %h
prints: Hash $var = {}
Hash $var = {}