Don't ask to ask, just ask | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
When a scalar ($foo, $foo[$i], $foo{$k}) is undefined and it is used as a reference (@$foo, $foo->[$i], ${$foo}[$i], %$foo, $foo->{$k}, ${$foo}{$k}, $$foo), two things can happen.
One possibility is that you get a warning. This occurs when you are trying to read from the dereferenced structure. (Technically, when the reference is used as an rvalue).
The other possibility is that the reference is autovivified. That means the appropriate structure (array, hash or scalar) is constructed and a reference to it is stored in the variable. This occurs when you are trying to write to the dereferenced structure. (Technically, when the reference is used as an lvalue).
Note then creating an alias to the dereferenced structure is an lvalue, and results in autovivification.
In reply to Re: Explaining Autovivication
by ikegami
|
|