in reply to walking a tree

Each successive pass of walktree clobbers the last results of fetchrow_array, since it executes on the same statement handle. One solution is to fetch all the rows at once, like this:
my ($subid, @children); while (($subid) = $children->fetchrow_array) { push @children, $subid; } for $subid (@children) { walktree ($subid); }
instead of:
while(my ($subid) = $children->fetchrow_array) { walktree($subid); }