http://www.perlmonks.org?node_id=357045

enoch has asked for the wisdom of the Perl Monks concerning the following question:

I just started thinking about this, and I know there is probably a very good answer that just hasn't occured to me yet, but why doesn't each automatically reset after loops are exited? It seems to me that that would make each DWIM. For example, this code:
#!/usr/local/bin/perl -wl my %hash=(a=>0, b=>1, c=>2); my $key; while (defined($key=each(%hash))) { last; } while (defined($key=each(%hash))) { print($key); }
Produces the output:
b c
Even though, I would think, the person writing that code would expect:
a b c
Is there a good reason not to reset the iterator that I just haven't thought of.