|
From: David L. <da...@la...> - 2007-02-02 22:11:18
|
Dan Faerch wrote: >> (By the way, this could be related to what you >> referred to in the code regarding resetting the hash.) > What im referring to, is that "while ... each" doesnt start from the top > of the hash the second time the function is called.. "each" only returns > last element. Using "keys" at top of the function fixes this oddity. There's nothing odd about this, it's standard Perl behaviour. each() stores its state on the hash, and returns the next element each (heh) time it is called until all the keys have been visited, at which point it returns undef. This can have surprising consequences. If you call each() from different areas in the code upon the same hash: the next call to each() returns the next item in from the hash's point of view, not the caller's point of view. Calling 'keys %hash' in void context is the only way to reset the iterator back to the beginning. Later, David |