On Sun, Jul 21, 2002 at 03:25:03PM +0200, Gerald Richter wrote: > > > > I am not having much luck getting a recursive function to work as it > > should. > > You need to localize your variables, otherwise they will be overwritten by > the second call the the sub:
When I do this, it appears as if it is not even processing the [* *] sections. Does it matter that I'm using EmbperlObject? I also get no debugging info output into embperl.log. The guts of what I'm doing follows: <table border=1> <tr> <td>   </td></tr> [- #Execute ({sub => 'printTree', param => ['0', '0'] }); printTree(0, 0); -] </table> [$ sub printTree $] [* local ($parent, $depth) = (@_) ? @_: (0,0); local $sth = $dbh->prepare( "select id, data from to_do where child_of = '$parent'" ); $sth->execute(); local %data = (); while ( local ($child, $data) = $sth->fetchrow_array() ) { $data{$child}{data} = $data; $data{$child}{depth} = $depth; } *] <pre> [- print OUT Dumper \%data -] </pre> [$ foreach $thing (sort keys %data) $] <tr> <td> [- print OUT "--" x $data{$thing}{depth}; -] [+ $thing +] :: [+ $data{$thing}{data} +] </td></tr> [- local $sth2 = $dbh->prepare( "select count(*) from to_do where child_of = '$thing'" ); $sth2->execute(); my ($children) = $sth2->fetchrow_array(); if ($children > 0) { my $newDepth = $data{$thing}{depth} + 1; #Execute ({ sub => 'printTree', param => [$thing, $newDepth] }); printTree($thing, $newDepth); } else { } -] [$ endforeach $] [$ endsub $] > > > > > [$ sub printTree $] > [* > local $parent ; > local $depth ; > local $sth ; > # add all variables here, that are declared with my in the Perl version > *] > > [- > > ($parent, $depth) = @_; > > print OUT "In PrintTree with depth = $depth, parent = $parent\n"; > ..... > > Note 1: You cannot use my here, because of the way EMbperl 1.3.x work > internaly (with EMbperl 2, you can use my) > Note 2: The local must be in a [* *] block, so the scope of the local is the > whole sub. > Note 3: Also [* *] are experimental in 1.3.4, it works without problems in > this case > > Gerald > > > ------------------------------------------------------------- > Gerald Richter ecos electronic communication services gmbh > Internetconnect * Webserver/-design/-datenbanken * Consulting > > Post: Tulpenstrasse 5 D-55276 Dienheim b. Mainz > E-Mail: [EMAIL PROTECTED] Voice: +49 6133 925131 > WWW: http://www.ecos.de Fax: +49 6133 925152 > ------------------------------------------------------------- > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- "Why do so many otherwise intelligent people look for answers to serious questions in systems purely of their own devising, which are able to prove on their own terms that they don't even have them? Mathematics, logic, science: they're useful servants, but exceptionally bad masters." --Simon Cozens --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]