From each docs:
When the hash is entirely read, a null array is returned in list context (which when assigned produces a false (0) value), and undef in scalar context. The next call to each after that will start iterating again. There is a single iterator for each hash, shared by all each, keys, and values function calls in the program; it can be reset by reading all the elements from the hash, or by evaluating keys HASH or values HASH.
Perhaps you don't like it, but it's documented.
If you want each to restart, you need to finish reading.
Put a my $x = keys %hash; between the two loops, and it will work as you expect.
In reply to Re: Why Doesn't each() DWIM?
by Anonymous Monk
in thread Why Doesn't each() DWIM?
by enoch
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |