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

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

Thread Previous | Thread Next
Vincent Pit
June 8, 2010 13:00
Re: [perl #75596] Iterator not reset on array assignment
Message ID:

> 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


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About