in reply to Strange behaviour of interpreter when dereferencing an undefined value
References in lvalue context autovivify.
%{ $a } in lvalue context is effectively %{ $a //= {} }
@{ $a } in lvalue context is effectively @{ $a //= [] }
For example,
>perl -MData::Dumper -E"my $ref; $ref->{a}{b} = 'c'; print Dumper $x;" $VAR1 = { 'a' => { 'b' => 'c' } };
As you can see, $x->{a}{b} in lvalue context is effectively ( ( $x //= {} )->{a} //= {} )->{b}.
You can control the behaviour using the autovivification module. (Don't file a bug report.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Strange behaviour of interpreter when dereferencing an undefined value
by kejv2 (Acolyte) on Nov 03, 2014 at 20:43 UTC | |
by ikegami (Patriarch) on Nov 04, 2014 at 03:38 UTC |