in reply to Why Doesn't each() DWIM?

But actually, you probably don't care what the each state at the end of your loop is. You care about the state at the beginning, so you will know that you potentially process all elements. And these two are only the same if you only use each inside loops.

However, it's perfectly ok to have code like:

# Suppose I know the hash has at least two entries, and # it's freshly restarted # Process first entry my($tag, $val) = each %hash) ; do_something($tag, $val); #Process second entry ($tag, $val) = each %hash; do_something($tag, $val); more_processing();
No loop here, so I don't suppose you would want to change the each semantics here.

But now suppose more_processing calls your while loop using each, which can also be called from other points in the program. You will still have the problem of not knowing the state, even with your proposed modification to the semantics of loops/each. So you'd have to reset the hash anyways.

So in short, I don't think your proposal would make the use of each easier, while the current sometimes useful behaviour would be lost. So all in all your proposal would be a loss.