To elaborate, the problem is that the hash is recreated each time, which means the internal iterator is also recreated each time. The same behavior will show up for keys() and values(), as well.
My criteria for good software:
Does it work?
Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
The same behavior will show up for keys() and values(), as well.
Incorrect. keys() and values() are not iterators. They return lists composed of data from the hash argument. When used in a 'for' loop, they only get called once.