Keep It Simple, Stupid | |
PerlMonks |
Re: Autovivification Oddityby oiskuu (Hermit) |
on Feb 11, 2018 at 15:07 UTC ( [id://1208959]=note: print w/replies, xml ) | Need Help?? |
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.
And to abuse it a little further: a slice in scalar context (imposed by dereference) yields its last value, so for instance
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].
In Section
Seekers of Perl Wisdom
|
|