New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
undefined scalar doesn't cause fatal error when defererenced as array #14580
Comments
From @dkCreated by @dkHello, It seems that we've hit a discrepancy in how undefined scalars are perl -E 'use warnings; use strict; use Data::Dumper; my $array_ref=undef; say Dumper($array_ref); foreach my $element (@$array_ref) { say $element } say Dumper($array_ref)' produces $VAR1 = undef; $VAR1 = []; where we would expect at least a fatal error like "Can't use an undefined value as an ARRAY reference" perl -E 'use warnings; use strict; use Data::Dumper; my $array_ref=undef; say Dumper($array_ref); foreach my $element (()=@$array_ref) { say $element } say Dumper($array_ref)' then it dies as expected. Versions up to 5.20 are affected. Sincerely Perl Info
|
From @jkeenanOn Fri Mar 13 02:33:22 2015, int32 wrote:
And to demonstrate that this is not just another bug in Data::Dumper: ##### $ perl -Mstrict -MData::Dump=pp -E 'my $array_ref=undef; pp($array_ref); for my $el (()=@$array_ref) { say "<$el>" } pp($array_ref);' -- |
The RT System itself - Status changed from 'new' to 'open' |
From bitcard@profvince.com
The list over which a for loop iterates is evaluated in lvalue context, because its elements can be changed by assigning to $_ (or whatever topic variable you use). Knowing this, what you observe is just the usual autovivification behaviour. In particular, note that both : @$array_ref = (); do not cause the "Can't use an undefined value as an ARRAY reference" stricture exception either, for the same reasons. It is pretty unrealistic to consider that this behaviour will ever change (it'd require a lot of work, would probably cause an important performance hit, and would break a lot of existing code), so I suggest closing the ticket. Vincent |
From @ikegamiOn Sat, Mar 14, 2015 at 7:22 PM, Vincent Pit via RT <
I don't see how it would cause a performance hit or break a lot of existing That said, I don't see a problem here. Especially since the behaviour can |
From @ikegamiOn Sun, Mar 15, 2015 at 8:43 PM, Eric Brine <ikegami@adaelis.com> wrote:
It would definitely cause problems to make it fatal, though. That said, I don't see a problem here. Especially since the behaviour can
|
Migrated from rt.perl.org#124060 (status was 'open')
Searchable as RT124060$
The text was updated successfully, but these errors were encountered: