Most abundant question first - the keys($table{$table}): One of the later posters was right - it's meant to be %{$tables{$table}}. Though in the actual code it's (%$table) - I changed it to make it slightly more readable (when i wrote the first version of the code, i was still getting the hang of using variables as variable names {is there a name for this practise?}, and haven't been brave enough to change all the legacy code - if i were to do it again, this is how it would look).
> First look at the obvious. buildParentSQL can print stuff before buildSQL if the loop in buildSQL doesn't execute
I think you've started me on the right track here - There could be no children left under the first child at level 3, so it drops back to level 2, runs parentSQL, and then moves into another child at level 3!
While this arguably still shouldn't account for what I'm seeing, combine it with an unfortunate sequence of foreign key relationships, and it's quite possible for a table to called as a parent, before it gets called as a child. The solution here will be to pull parentSQL out of buildSQL, and borrow of lot of the code from it for the looping. Slightly less elegant, but this script has long since passed the asethetic phase of its life!
> On an unrelated note,
> sub buildParentSQL ()
> should be
> sub buildParentSQL
> Don't use prototypes unless you must, especially incorrect prototypes.
Noted - cheers! Not sure why i do it this way - probably a habit picked up from shell scripting
> If it is long, use readmore tags.
???
Will try running with strict, warnings, non-embedded recursion and all the other suggestions here today, and update you with my progress.
It's a large and ugly script to setup the data - I barely understand it myself these days, so i don't want to pain you with it - the guts of it is though:
- read in a human readable dump of the database schema (dbschema -d <db> -t all, for the informix ppl out there)
- Parse it, to get: a hash of tables and their primary keys ($pkeys{<table>}=<primary-key>), a hash of tables, and their columns (push(@{$cols{$table}},<col>), a hash of children and foreign keys ($<table>{$child}=<foreign-key>).
(this one is the hash you are seeing in the loop.
- Call buildSQL for the start table.
- Enter recursive hell.
I'll post again in a few hours with an update.
In reply to Re^2: Two recursive functions returning in unexpected order
by Anonymous Monk
in thread Two recursive functions returning in unexpected order
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |