$ perl -le " use warnings; use strict; my $foo; $foo++; print $foo "
1
So these two examples are not comparable. And I believe the second example actually is where we see autovivication at work.
Yes, they really are exactly comparable, and no, the second example is not autovivification any more than the first example is autovivification -- neither is autovivification
Growing an array is not autovivification. JavaScript doesn't support autovivification , try it if you have firefox ( Ctrl+Shift+K )
[03:41:08.755] var noauto = [ 0, 1 ]; noauto[ 6 ] = 66; noauto ;
[03:41:08.764] [0, 1, , , , , 66]
[03:43:06.834] noauto[2].failToAutoVivify = 12; noauto;
[03:43:06.843] TypeError: noauto[2] is undefined
JavaScript supports growing arrays but not autovivification, but perl does supports it, undef becomes a hashref if you treat it like a hashref $ perl -MData::Dump -le " my $auto = [ 0, 1 ]; $$auto[6]=66; dd $auto;
+ "
[0, 1, undef, undef, undef, undef, 66]
$ perl -MData::Dump -wle " my $auto = [ 0, 1 ]; $$auto[6]=66; $$auto[2
+]{VIVIFY}=12; dd $auto; "
[0, 1, { VIVIFY => 12 }, undef, undef, undef, 66]
|