Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: while( each ... ) caught in an infinite loop

by BrowserUk (Patriarch)
on Mar 31, 2009 at 10:44 UTC ( [id://754382]=note: print w/replies, xml ) Need Help??


in reply to while( each ... ) caught in an infinite loop

You are calling the subroutine again each time the while loop iterates, which means you are constructing and returning a new anonymous hash for each iteration. As the hashref returned is to a newly construct hash, its iterator starts from the beginning each time.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re: while( each ... ) caught in an infinite loop

Replies are listed 'Best First'.
Re^2: while( each ... ) caught in an infinite loop
by jettero (Monsignor) on Mar 31, 2009 at 10:47 UTC

    Which, I believe can be constructed from a much smaller example:

    while( my @a = each %{{ a=>'b' }} ) { print "forever\n" }
    .

    -Paul

Re^2: while( each ... ) caught in an infinite loop
by johngg (Canon) on Mar 31, 2009 at 12:37 UTC

    Thank you. The "small bugette" is in my brain, obviously. I wonder how it is that I can spend hours on a problem and dismally fail to spot the obvious :-(

    Thanks again.

    JohnGG

      It's not at all intuative. I may never have noticed this myself if it wasn't for reading about it in DBM::Deep.

      -Paul

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-26 07:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found