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


in reply to Re^3: Array dereference in foreach()
in thread Array dereference in foreach()

Hi haukex,

Thank you to for your detailed explanation. That makes sense. However I found another interesting feature.

my $h; my $g; $h->{abc} = $g->{lkj}; print "h: ", Dumper(\$h), "\n"; print "g: ", Dumper(\$g), "\n";
and the output is
h: $VAR1 = \{ 'abc' => undef }; g: $VAR1 = \{};
The left side ($h) is autovivified and undef is assigned to key 'abc'. It is correct. But what has happened on the right? Is it semi-autovivified or what? Empty anonymous hashref is assigned to $g. Where is 'lkj'? Is $g->{lkj} in lvalue context? Why there is no exception?

Regards