in reply to Re: trouble with each and a hash of hashes
in thread trouble with each and a hash of hashes

As ccn quoted
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.
So if at all unsure just do
keys %{$patterns{$gen}})
before the while loop.
But, why does this not happen every time the subroutine is called -- just once in a while?
Is it possible that you sometimes return from the subroutine from inside the while loop?