Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: walking a tree

by blokhead (Monsignor)
on Nov 13, 2007 at 03:48 UTC ( #650433=note: print w/replies, xml ) Need Help??


in reply to walking a tree

Each recursive call to walktree uses the same $children statement handle. So most likely, each time a recursive call re-executes the $children statement, it clobbers whatever was pending for the caller in that statement handle. When the control returns to the caller, there is nothing left to iterate over.

If you think about how things happen sequentially, walktree only returns once $children->fetchrow fails. Then right after it returns, the first thing the caller tries to do is $children->fetchrow!

To fix this, either make new statement handles within each call to walktree, or else fetch all of the results from the $children query into an array before recursing at all.

blokhead

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://650433]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2017-03-28 10:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (328 votes). Check out past polls.