Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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.

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?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2020-05-31 11:21 GMT
Find Nodes?
    Voting Booth?
    If programming languages were movie genres, Perl would be:

    Results (173 votes). Check out past polls.