develooper Front page | perl.perl5.porters | Postings from July 2014

[perl #121677] Malfunction of delete @x[@y] when @x and @y are identical

Thread Previous
From:
James E Keenan via RT
Date:
July 4, 2014 01:15
Subject:
[perl #121677] Malfunction of delete @x[@y] when @x and @y are identical
Message ID:
rt-4.0.18-12422-1404436507-1051.121677-15-0@perl.org
On Thu Apr 17 09:32:26 2014, anno5@me.com wrote:
> I noticed that "delete @x[@y]" can go wrong in the special case when
> @x and @y are identical. Example:
> 
> use warnings;
>  my @array = (2, 1, 2);
> delete @array[@array]; # deleting from itself
> say "(@array)";
> 
> 
> The response is
> Use of uninitialized value in delete at ./ttt line 11.
> ()
> 
> The warning is unexpected and the resulting array ought to still have
> 2 on index position 0. Indeed, "delete @array[my @dup = @array]" shows
> the expected behavior.

I think this also is the expected behavior:

#####
my @array        = (2, 1, 2);
my @second_array = (2, 1, 2);
delete @array[@second_array]; 
say "(@array)";
##### Output:
(2)
#####

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=121677

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About