in reply to Why Doesn't each() DWIM?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Why Doesn't each() DWIM?
by BrowserUk (Patriarch) on May 27, 2004 at 21:51 UTC | |
|
Re:^2 Why Doesn't each() DWIM?
by Nkuvu (Priest) on May 27, 2004 at 21:15 UTC | |
|
Re: Re: Why Doesn't each() DWIM?
by enoch (Chaplain) on May 27, 2004 at 21:15 UTC | |
by duff (Parson) on May 27, 2004 at 21:46 UTC | |
by enoch (Chaplain) on May 27, 2004 at 22:37 UTC | |
by jepri (Parson) on May 27, 2004 at 21:34 UTC |