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
keys()/values() autovivify dereferenced undefined scalar #13120
Comments
From agalama@mailfish.deCreated by galama@mailfish.deWhen called with a dereferenced undefined scalar variable, keys() $ perl -MData::Dumper -e 'print Dumper($h); keys %$h; print Dumper($h)' The documentation says: "As a side effect, calling keys()/values() I am not sure if this is meant to imply that $h should point to a newly Perl Info
|
From @epaIt is certainly odd that keys or values succeeds when a simple % perl -E 'use warnings; use strict; my $a; my @x = keys %$a; say "ok"' On the other hand, dereferencing and looking up a value does autovivify: % perl -E 'use warnings; use strict; my $a; my $x = $a->{a}; say $a' |
The RT System itself - Status changed from 'new' to 'open' |
From @ikegamiOn Tue, Jul 23, 2013 at 7:57 AM, Ed Avis via RT
Sub arguments and some function arguments are lvalues. lvalue derefs This is behaving properly.
|
From @ikegamiOn Tue, Jul 23, 2013 at 10:36 AM, Eric Brine <ikegami@adaelis.com> wrote:
|
From @epaEric Brine <ikegami <at> adaelis.com> writes:
That doesn't really explain *why* the argument to keys and values should be At first sight, getting the keys and values together with %$a doesn't seem The 'scalar' builtin used to get array length doesn't autovivify: % perl -E 'use warnings; use strict; my $a; my $x = scalar @$a' Is it documented which builtins take lvalues and which rvalues? -- |
From @ikegamiOn Tue, Jul 23, 2013 at 11:19 AM, Ed Avis <eda@waniasset.com> wrote:
Yes. But it turns out that most named ops don't.
So it doesn't appear to be as simple as I thought it was. |
From @epa...and to add another wrinkle, the autovivification for keys and values does % perl -E 'use warnings; use strict; my $a = {}; my @x = keys $a; say "ok"' But this might have been a deliberate decision for auto-deref, even if it -- |
From @ikegamiOn Wed, Jul 24, 2013 at 3:12 AM, Ed Avis <eda@waniasset.com> wrote:
It's never keys that does the autovivification, it's the dereference. In |
Migrated from rt.perl.org#118983 (status was 'open')
Searchable as RT118983$
The text was updated successfully, but these errors were encountered: