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

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

Thread Previous | Thread Next
From:
Vincent Pit
Date:
June 8, 2010 13:00
Subject:
Re: [perl #75596] Iterator not reset on array assignment
Message ID:
4C0EA145.9020102@profvince.com

> 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

Vincent.

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