Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: grep { } positional number of element

by bliako (Monsignor)
on Oct 24, 2022 at 13:22 UTC ( [id://11147643]=note: print w/replies, xml ) Need Help??


in reply to Re^2: grep { } positional number of element
in thread grep { } positional number of element

I think there is, or, at least, *was*, good reason why each was erased from our concsiousness. I do not know what the state of these bugs is today. I was definetely bitten by its non-reentrancy /sic/ several times in nested each loops.

Replies are listed 'Best First'.
Re^4: grep { } positional number of element
by Bod (Parson) on Oct 25, 2022 at 16:35 UTC
    good reason why each was erased from our concsiousness [sic]

    Thanks for bringing that to our attention 🙂

    It seems that each is OK provided we know for sure that the array or hash that is being iterated is not being modified during the iteration. Much of the time we can be sure of that I think. But, of course, it is easy to overlook that the data could be modified, particularly if each is used in a module.

      > Much of the time we can be sure of that I think.

      Only if you don't call any other routines from any other module while using each.

      I seem to remember that one of the dumper modules messed with the each counter.

      Similarly if you export your sub and the data structure is passed as variable. Than the importing code could get into trouble using each.

      Otherwise you need to copy the hash/array beforehand.

      (all of this would be much easier if there was a way to localize the internal counter)

      update

      in short, each X is only safe if X is never passed around.

      Cheers Rolf
      (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
      Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-19 15:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found