Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by Thilosophy (Curate)
on Jul 15, 2005 at 09:38 UTC ( [id://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.

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://475154]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-03-29 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found