in reply to Re: LoH Incrementing Autovivification
in thread LoH Incrementing Autovivification
In a scalar context, keys is returning the number of keys, which is 1 when it's first called. In the second line, we're going under the assumption that $_->{1} is a valid hashref, and checking for the 'length' key of that hashref. Perl has to oblige ("autovivification"), so it creates the necessary hashref to make $_->{$key}{'length'} a legal expression, thus giving us a new key (1) in the hashref referred to in $_.my $key = keys %{$_}; my $val = $_->{$key}{'length'};
|
|---|