in reply to side effects of map
First: autovivification occurs when an lvalue (cling to this word in the paragraphs below) contains references that did not previously exist. So this:
works because the reference keys are autovivified to provide a slot for the value 'blue'. So far, so good...my $href; $href->{smith}{john}{eyecolor} = 'blue';
But interestingly, even though it does not appear to be an lvalue, the following also causes keys to magically appear:
In the process of looking for a value to return, Perl creates (autovivifies) the 'smith' and 'john', keys and then returns undef (eyecolor) to be assigned to $color. The Camel book (3rd Edition, p. 710) describes this while suggesting that this behavior may be "fixed in a future release".my $href; my $color = $href->{smith}{john}{eyecolor};
The same goes for:
my $href; if (exists $href->{smith}{john}{eyecolor}) { # do something }
lvalue? bug? You be the judge.
So... to get closer to your code, if we said:
We would not thereby create a zero-th element but we would cause the undef $aref to autovivify as a reference to an anonymous array in the process of looking for the non-existent zero-th element.my $aref = undef; my $a = $$aref[0];
If you have made it this far, it's only one more step into the fog to suggest that (just as with the previous example):
is going to look for a possible $$aref[0] ...and in the process autovivify the $aref as an actual reference to an anonymous array (containing no elements).my $aref = undef; my @a = map {$_} @$aref;
Ain't Perl great?
HTH
|
|---|