Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^6: self-feeding infinite loop

by Dominus (Parson)
on Aug 20, 2007 at 20:01 UTC ( #633927=note: print w/ replies, xml ) Need Help??


in reply to Re^5: self-feeding infinite loop
in thread self-feeding infinite loop

The point wasn't about indexes being numbers or not...
Yes, I understood that you had missed this essential point. That was why I tried to bring it to your attention.

it was that modifying an array while iterating over it is dangerous
As I tried to suggest in my original message, it isn't dangerous. Sorry this wasn't clear to you.

I understand that you fear this construction because you don't understand it, and that you have a faulty mental model of the way foreach loops are processed, which leads you to an incorrect expectation of what they will do when the underlying array is modified. However, this fear is only your private emotion. It is real, but it does not extend outside of yourself. In particular, you cannot conclude from the fact of your fear that the practice is actually "dangerous".


Comment on Re^6: self-feeding infinite loop
Re^7: self-feeding infinite loop
by eric256 (Parson) on Aug 20, 2007 at 20:45 UTC

    dangerous: Being able or likely to do harm.

    I don't disagree that my mental model might be flawed. However, given my internal concept of foreach it is likely that modifying the array while using for each is dangerous (likely to do harm).

    You could certainly make your points without splitting hairs on the meanings of words. The fact is perl has foreach to hide the use of an index to iterate over an array, makeing most array usage much easier in the process. I believe that this act of obscuring the underlying use of indexes would also mean that the actual implementation is not a reliable way to decide how it will respond when you modify the array. Since the documentation explicitly says not to do it and I don't know how its implemented internally, I'll stick with not modifying it and I don't have to attribute it to fear or a faulty mental model, it's just good since.


    ___________
    Eric Hodges

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-08-29 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (280 votes), past polls