in reply to LoH Incrementing Autovivification

Ah, thank you merlyn. Of course, I don't have a good logical reason why I did it. Chalk it up to some subconscious oversight in combination with knowing that I was only going to get back one key.

Thank you very much

Replies are listed 'Best First'.
Re: Re: LoH Incrementing Autovivification
by Fastolfe (Vicar) on Nov 17, 2000 at 20:34 UTC
    For those that don't quite get what happened:
    my $key = keys %{$_}; my $val = $_->{$key}{'length'};
    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 $_.