in reply to Re^2: Should this happen?
in thread Should calling 'exists' create a hash key?

In the case of $a[100][42] = pi, obviously there is autovivification. That has no difference from $a->{"a"}{"a"} = pi.

Whether $a[100] makes $a[0] through $a[99] autovivified is not a black white thing, and I am not the first person who classifies that as autovivification. When it is valid to look at this from a perl internal point of view as you did, it is at least not less valid to look at this from a logical point of view. Look at this:

use strict; use warnings; my @as; $as[10] = 0; for my $a (@as) { print "."; }

this will print 11 dots, not 1 or 12.

To further pursuit a single correct answer to this question is not very useful, as autovivification is not a clearly defined concept, but rather a commonly used not-clearly-defined terminology that is often expressed through examples.

Replies are listed 'Best First'.
Re^4: Should this happen?
by Fletch (Bishop) on Sep 20, 2005 at 13:57 UTC

    Quoting perldoc perlref:

    This is one of the cases we mentioned earlier in which references could spring into existence when in an lvalue context. Before this statement, $array[$x] may have been undefined. If so, it's automatically defined with a hash reference so that we can look up "{"foo"}" in it. Likewise "$array[$x]->{"foo"}" will automatically get defined with an array reference so that we can look up "[0]" in it. This process is called autovivification.

    Going by the documentation it would seem to have a specific, clear definition: autovivification is the process of automatically creating a new reference (hashref or arrayref) to an anonymous data structure in an lvalue context. Automatically extending an array doesn't create a reference to a new anonymous data structure, it merely increases the size of an existing one.

    But yes, this is degenerating into pedantry . . . :)