pme has asked for the wisdom of the Perl Monks concerning the following question:
This tiny code fails with "Can't use an undefined value as an ARRAY reference" exception.
but this one works as expected (does nothing)use strict; use warnings; use diagnostics; my $href = { list => undef, }; my @a = @{$href->{list}}; # fails here foreach my $i (@a) { print "$i\n"; }
Could you explain me what makes the difference here? Thanks.use strict; use warnings; use diagnostics; my $href = { list => undef, }; foreach my $i (@{$href->{list}}) { print "$i\n"; }
My perl is 5.18.2.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Array dereference in foreach()
by haukex (Archbishop) on Nov 14, 2017 at 14:10 UTC | |
by Anonymous Monk on Nov 14, 2017 at 16:02 UTC | |
by haukex (Archbishop) on Nov 14, 2017 at 16:20 UTC | |
by pme (Monsignor) on Nov 16, 2017 at 09:54 UTC | |
by choroba (Cardinal) on Nov 16, 2017 at 10:20 UTC | |
| |
by 1nickt (Canon) on Nov 16, 2017 at 12:19 UTC |