in reply to Re^5: Keys() required to autovivify?
in thread Keys() required to autovivify?

Autovivification (in the case of a hash) is when a key is added to a hash where previously that key wasn't there. Just using $h{x}, as in $val = $h{x} does not add a new key to the hash. It simply assigns the default undef value to $val. Referencing through a key does autovivify the all but the last key:
#!/usr/bin/perl my %h; my $val = $h{x}{y}; use Data::Dumper; print Dumper \%h;
Output:
$VAR1 = { 'x' => {} };
Apparently, not only does $h{x} not autovivify $h{x}, but even %{$h{x}} does not autovivify $h{x} (you have to turn off strict and -w first):
#!/usr/bin/perl my %h; %{$h{x}}; use Data::Dumper; print Dumper \%h;
Output:
$VAR1 = {};
But, using keys() causes %{$h[x}} to autovivify $h{x}.
#!/usr/bin/perl -w use strict; my %h; keys %{$h{x}}; use Data::Dumper; print Dumper \%h;
Output:
$VAR1 = { 'x' => {} };