Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Ouch! Each! Reentrant it is not

by Thilosophy (Curate)
on Jul 15, 2005 at 09:38 UTC ( #475154=note: print w/ replies, xml ) Need Help??


in reply to Re: Ouch! Each! Reentrant it is not
in thread Ouch! Each! Reentrant it is not

Rewind it before using each.

I did that at first, but then I changed it to rewind after use.

Because if you rewind it only before, and then leave the iterator "open", your own piece of code is fine, but it will greatly confuse the next person who happens to call keys, values or each. So I decided that cleaning up after myself is the better way here.

Update As pointed out by ysth, it would only greatly confuse any other users of each, and not affect keys or values.


Comment on Re^2: Ouch! Each! Reentrant it is not
Select or Download Code
Re^3: Ouch! Each! Reentrant it is not
by ysth (Canon) on Jul 15, 2005 at 09:45 UTC
    keys and values don't depend on the iterator, just each.
      Experimentation proves you right. Interesting. I must have mis-interpreted the perldoc:

      There is a single iterator for each hash, shared by all "each", "keys", and "values" function calls in the program.

        That just indicates that keys and values affect the iterator (resetting it).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://475154]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2014-09-15 10:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (146 votes), past polls