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

Re: foreach argument modification inside loop, followed by return from loop

by BillKSmith (Chaplain)
on Jul 10, 2013 at 13:08 UTC ( #1043463=note: print w/ replies, xml ) Need Help??


in reply to foreach argument modification inside loop, followed by return from loop

I first saw this issue severl years ago on the newsgroup perl.misc. Its use greatly simplified the solution to a posted problem. The consensus then was the same as today. It may work, but don't do it!

Bill


Comment on Re: foreach argument modification inside loop, followed by return from loop
Re^2: foreach argument modification inside loop, followed by return from loop
by vsespb (Hermit) on Jul 10, 2013 at 13:33 UTC
    Are you sure it was about returning from loop immediately after modification of array? Can you find the link? Very interesting!
      Sorry, It was much too long ago for my memory. I have not had access to a newsgroup server for some time. I do not even rember my old username. It was written by a very active user named PerlGurl (not sure of spelling). I reasonably certain that the application was randomizing an array. Notes that I had did not survive a hard drive failure.
      Bill
        I found something.

        https://groups.google.com/forum/#!searchin/comp.lang.perl.misc/randomizing$20/comp.lang.perl.misc/D8Znz7CbCyg/ZXcyK3OTUEIJ

        PerlGuru + something about randomizing array + foreach+splice+last

        'If any part of LIST is an array, "foreach" will get very confused > if you add or remove elements within the loop body, for example with > "splice". So don't do that.' > > Your testing seems to prove that this is a special case, certainly a > very useful one. > Please explain what makes it special. The 'last' makes it special. By exiting the loop there is no opportunity for confusion.
        But I did not find see "Anyway, don't do it, even with "last"" advices :(

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2014-12-27 23:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls