Problems? Is your data what you think it is? | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Fellow Monks,
I have just spent an hour debugging a very strange problem, only to discover that I have been bitten by the behaviour of each. While all this is properly documented (each), I was not aware of it, so I thought I'd bring it up here as a caveat to remember. The subroutine in the following snippet works only once (or rather every other time). After the first call, it dies: What happens here is that the subroutine does not search through the whole hash (it short-cicuits for performance reasons by returning the solution as soon as it has found it), and as a result, the next call to each on the same hash (even in completely different parts of the code!) will not start at the beginning again, but pick up where the first call left off. Solution: Either go through the whole hash, or rewind it after using each:
In reply to Ouch! Each! Reentrant it is not by Thilosophy
|
|