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

Thanks to everybody who gave me advice.

Yes, I am calling the subroutine many times (once for each input line matching certain conditions).

Yes, I do NOT change the HoH in between.

Yes, if I use keys instead of print Dumper I get the same effect (things work).

So, I guess the problem is that I need to reset the iterator.

But, why does this not happen every time the subroutine is called -- just once in a while?

Also, is there a standard way to reset the iterator?

Thanks again.

Marco

Replies are listed 'Best First'.
Re^2: trouble with each and a hash of hashes
by shenme (Priest) on Sep 11, 2004 at 18:57 UTC
    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?