It's pretty simple. I don't know how it's documented, since I learned it mostly
by folklore (and by watching the response to bug reports on P5P {grin}).
When a variable containing undef (or a new element of an array
or hash) is used in an "lvalue-context" (on the left side of an assignment,
for example) as a reference, a reference to the appropriate anonymous thingy
is inserted and the operation continued, rather than throwing an error for
an attempt to dereference undef.
So, push @$x, 35 works even if $x is undef, because
we're about to dereference $x while trying to store something.
It's really just an extension of the principle that
$last_name{"fred"} = "flintstone";
works, even though I didn't originally create the element with that key.
-- Randal L. Schwartz, Perl hacker |