Open p5pRT opened 18 years ago
This is a bug report for perl from ken@mathforum.org\, generated with the help of perlbug 1.34 running under perl v5.8.1.
As the following three one-liners demonstrate\, perl is autovivifying some hash entries in a case it seems like it ought not to:
% perl -le 'sub foo{} foo(@x{'a','b'}); print for keys %x'
b
a
% perl -le 'sub foo{} foo($x{a},$x{b}); print for keys %x'
% perl -le 'sub foo{$_=5 for @_} foo($x{a},$x{b}); print for keys %x'
a
b
The main difference is between the first two examples\, which my intuition tells me ought to be equivalent. The third example shows that even when not using slices (and thus not autovivifying unnecessarily)\, @_ still manages to create read/write aliases to the original hash entries.
Credit goes to Thomas L. Shinnick\, who figured out why File::Spec->tmpdir was autovivifying an undef value for $ENV{TMPDIR}.
-Ken
This is still true in 5.16.
The RT System itself - Status changed from 'new' to 'open'
On 21 June 2012 19:47\, Jesse Luehrs via RT \perlbug\-followup@​perl\.org wrote:
This is still true in 5.16.
But why is it a bug? Afaik it is supposed to happen.
sub one { $_=1 for @_ }
one(@foo{qw(x y z)});
print $_\,":"\, $foo{$_}\, $/ for keys %foo;
__END__
y:1 x:1 z:1
-- perl -Mre=debug -e "/just|another|perl|hacker/"
Sure\, it's clearly necessary in that case. But:
Sure, it's clearly necessary in that case. But:
sub nop { }
my (%foo, %bar);
nop(@foo{'a', 'b'});
nop($bar{'a'}, $bar{'b'});
say "foo:";
say for sort keys %foo;
say "bar:";
say for sort keys %bar;
__END__
foo:
a
b
bar:
I don't see a reason why %foo
and %bar
should end up being any different
there.
-doy
Ok\, I see. That makes sense. Maybe rename the bug?
Yves
@doy @demerphq
Dicussion in this RT petered out about a year ago. Do you see any way we could move this ticket toward resolution?
Thank you very much. Jim Keenan
This is on my to-do list\, but rather low. Please leave it open if you will.
--
Father Chrysostomos
In case someone wants to beat me to it\, it’s matter of extending defelem magic (search for PERL_MAGIC_defelem in pp_hot.c) to hslice and aslice.
--
Father Chrysostomos
On Tue\, Jun 18\, 2013 at 8:40 AM\, Father Chrysostomos via RT \< perlbug-followup@perl.org> wrote:
In case someone wants to beat me to it\, it’s matter of extending defelem magic (search for PERL_MAGIC_defelem in pp_hot.c) to hslice and aslice.
As far as I recall similar situation applies to for loops:
perl -E '1 for @h{qw(1 2 3)}; say %h' 132
But it spreads over more operations:
perl -E '1 for $h{a}\, $h{b}; say %h' ab
Sorry\, if it's not releated.
Migrated from rt.perl.org#37441 (status was 'open')
Searchable as RT37441$