develooper Front page | perl.perl5.porters | Postings from August 2010

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

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
August 2, 2010 08:00
Subject:
Re: [perl #75596] Iterator not reset on array assignment
Message ID:
20100802150003.GV48531@plum.flirble.org
On Tue, Jun 08, 2010 at 10:00:05PM +0200, Vincent Pit wrote:
> 
> > The iterator can be reset by calling keys(). This is efficient in void
> > context.
> >   
> 
> This is besides the point. The hash iterator is reset when an hash is
> emptied (because hv_clear needs the iterator to walk the keys). I
> believe it's natural to expect the same for arrays.
> 
>     $ perl -E 'my %h = (a => 1, b => 2); my ($k, $v) = each %h; say "$k:
> $v"; %h = (a => 3, b => 4); while (my ($k, $v) = each %h) { say "$k: $v" }'
>     a: 1
>     a: 3
>     b: 4

I agree with Vincent's assessment.
Is the fix for this as simple as adding a vtable entry for PERL_MAGIC_arylen_p
that triggers at the right time? (Clear, I assume, but I'm not certain)

Patches particularly welcome (from anyone, not just Vincent), as this seems
like a fairly self-contained task.

Nicholas Clark

Thread Previous | Thread Next


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