in reply to Why Doesn't each() DWIM?
However, it's perfectly ok to have code like:
No loop here, so I don't suppose you would want to change the each semantics here.# 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();
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.
|
|---|