in reply to Autovivification Oddity
Not an answer to your question, but I'd like to point out a thing about dereferencing.
You can control (avoid) autovivification by taking a slice instead of plain dereference. One-element slices may raise a warning, though, so I guess this might count as a hack.
$ perl -wMstrict -MData::Dump -e' my $x = $#{$$a{list}}; dd $a' { list => [] } $ perl -wMstrict -MData::Dump -e' my $x = $#{@$a{list}}; dd $a' Can't use an undefined value as an ARRAY reference at -e line 1.
And to abuse it a little further: a slice in scalar context (imposed by dereference) yields its last value, so for instance
$ perl -MData::Dump -e' my %h = map {$_ => {v => "x$_"}} qw(a b c); dd + @h{qw(a b c)}->{v};' "xc"
Update. Forgot to mention: with recent enough perls that support postderef, one can change a straight deref into a slice simply by making an -> into ->@. Thus you may prevent autovivification at any level, e.g. $x->@{a}->@[5].
|
|---|