Thanks a lot for your code. I need to apologize for not using it, because I ended up with my own solution. What I do now is instead of storing the whole array, I just shift the value off and store it in a hash table. In other words I am using parallel arrays with identical subscripts, and this seems to work fine recursing over the whole structure.
But I'll add a bookmark to your solution because it does answer the question by storing the reference to the array. Thanks!
Just for laughs, here is my code. I am recursing through 6 levels this way, but I feel it will work for any number of levels:
$query[$level]->execute;
while((@level_data)=$query[$level]->fetchrow_array)
{
%treepos = (); # reset the whereclause for a new branch
%pathpos = ();
$treepos{$key} = shift @level_data;
$pathquery[$level] = &path_sql($childlevel,$treepos{$key});
while((@path_data)=$pathquery[$level]->fetchrow_array)
{
$pathpos{$key} = shift @path_data;
&level_proc;
}
}
sub level_proc {
$query[$childlevel] = &level_sql($childlevel,$treepos{$key});
while((@level_data)=$query[$childlevel]->fetchrow_array)
{
&setlevel($childlevel);
$treepos{$key} = shift @level_data;
&path_proc;
$treepos{$key} = undef;
&setlevel($parlevel);
}
sub path_proc {
$pathquery[$level]= &path_sql($pathpos{$parkey},$treepos{$key}
+);
while((@path_data)=$pathquery[$level]->fetchrow_array)
{
$pathpos{$key} = shift @path_data;
&children_proc;
}
}
}
sub children_proc {
&children_sql($pathpos{$key},$childlevel);
&level_proc;
}
|