Re: [perl #75596] Iterator not reset on array assignment

[email protected] (Abigail)
Newsgroups perl.perl5.porters
Message-ID <20100608114955.GA22742@almanda>
On Mon, Jun 07, 2010 at 02:27:33PM -0700, [email protected] wrote:
> # New Ticket Created by  [email protected] 
> # Please include the string:  [perl #75596]
> # in the subject line of all future correspondence about this issue. 
> # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=75596 >
> 
> 
> This is a bug report for perl from [email protected],
> generated with the help of perlbug 1.39 running under perl 5.10.1.
> 
> 
> -----------------------------------------------------------------
> [Please describe your issue here]
> 
> Perl doesn't reset the array iterator when the array is cleared :
> 
>     $ perl5.12.1-64 -M5.012 -E 'my @a = "a" .. "c"; my ($i, $v) = each @a; say "$i: $v"; @a = "A" .. "C"; ($i, $v) = each @a; say "$i: $v"'
>     0: a
>     1: B
> 
> The issue is still present in 5.13.1.


Interesting. My first reaction was, "it probably should reset the iterator".
But then I wondered, what if one had written C<< $a [1] = "B" >> instead of
C<< @a = "A" .. "C" >>? Should the iterator be reset then? What on
C<< @a [0 .. 2] = "A" .. "C" >>? Should shift, pop, push, unshift, splice
reset the iterator? Currently none of them do.

Even C<< undef @a; @a = "A" .. "C"; >> doesn't reset the iterator.


Abigail
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.