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


in reply to Re: Ouch! Each! Reentrant it is not
in thread Ouch! Each! Reentrant it is not

Rewind it before using each.

I did that at first, but then I changed it to rewind after use.

Because if you rewind it only before, and then leave the iterator "open", your own piece of code is fine, but it will greatly confuse the next person who happens to call keys, values or each. So I decided that cleaning up after myself is the better way here.

Update As pointed out by ysth, it would only greatly confuse any other users of each, and not affect keys or values.