Re: [perl #75596] Iterator not reset on array assignment
[email protected] (Vincent Pit)
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <[email protected]> |
> 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.