in reply to Two recursive functions returning in unexpected order

First look at the obvious. buildParentSQL can print stuff before buildSQL if the loop in buildSQL doesn't execute. Are you sure that (keys($tables{$table})) is what you want in there ? Hard to tell w/o knowing what $tables is, but it looks a little fishy.

Such problems in general are easy to resolve with extra printouts. In the beginning of every function insert a printout of "foo called" (possibly with its arguments) and in the end a printout of "foo returns" (possibly with what it returns). Then, run on a small example - this will sure clear things up for you.

  • Comment on Re: Two recursive functions returning in unexpected order

Replies are listed 'Best First'.
Re^2: Two recursive functions returning in unexpected order
by Argel (Prior) on May 11, 2005 at 18:43 UTC
    Such problems in general are easy to resolve with extra printouts.

    I usually like to use a subroutine for this and then call it at the beginning of every other subroutine in the script.

    sub whoami { print "DEBUG: ".(caller(1))[3]."\n" if $DEBUG > 0; } sub dostuff { whoami(); <snip> }
    -- Argel