kejv2 has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I have come across this strange (at least to me) behaviour of perl interpreter. Let me give you an example:
This unsurprisingly gives a run time error "Can't use an undefined value as a HASH reference". But then I would think that so does any of these:perl -We'use strict; my $a; my $b = %{ $a }'
perl -We'use strict; my $a; my @b = map { $_ } %{ $a }' perl -we'use strict; sub foo {}; my $a; foo( @{ $a } )'
Instead it seems that perl in this case (function context?) just translates those hash or array dereferences to empty structure and gives no error.
Can somebody explain what is going on here?
(Tested with perl 10, 14 and 20.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Strange behaviour of interpreter when dereferencing an undefined value
by ikegami (Patriarch) on Nov 02, 2014 at 11:00 UTC | |
by kejv2 (Acolyte) on Nov 03, 2014 at 20:43 UTC | |
by ikegami (Patriarch) on Nov 04, 2014 at 03:38 UTC | |
|
Re: Strange behaviour of interpreter when dereferencing an undefined value (missing warning, perl doesn't warn for all cases)
by Anonymous Monk on Nov 02, 2014 at 09:56 UTC |