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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."
  • 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