No such thing as a small change | |
PerlMonks |
Re: Array mysteriously growing (autovivification explained)by Aristotle (Chancellor) |
on Mar 11, 2006 at 07:47 UTC ( [id://535908]=note: print w/replies, xml ) | Need Help?? |
Congratulations, you have stumbled onto autovivification. :-) To expand on swkronenfeld’s point, this always happens when you dereference an undefined value “en passant”:
This is so you can build deep structures without a lot of checks:
If Perl didn’t autovivify, you would have to write this like so:
Most of the time this implicit creation of anonymous data structures on access is very convenient. However, you have to be mindful of it when you are writing condition checks. Makeshifts last the longest.
In Section
Seekers of Perl Wisdom
|
|