array problem (second try)

2001-09-20 Thread Vilts

Hello,

Sorry if this is coming twice. In apache/mod_perl
handler i use recursive function to parse a tree and
find it's root (umm, uppermost ID). If script goes one
level up it pushes it's ID to array, after it's
finisthed I pop last ID from array.  Now
first time it runs it works just fine, but after that
array contains only first ID that was pushed there.
What could cause this? To make it little
clearer I add table and script. So, first time
@maks_id is 18 17 16 1 and $temp_id = 1, but later
array it just 18 and id is 18 too, I don't like
it :(. Oh, and if someone has any good ideas how to
improve this tree parsing algorithm then i'd be happy
to hear about it :).


table:

mysql  SELECT categ_id, parent FROM categories;
+++
|   categ_id | parent |
+++
|  1 |  0 |
| 16 |  1 |
| 17 | 16 |
| 18 | 17 |
+++

program:

sub maksimum {
   my ( $dbh, $kat ) = @_;
   my $counter = 0;
   my @maks_id = [ ];

   my $query = qq{ SELECT categ_id, parent, nimetus
FROM categories };
   my $sth = $dbh-prepare_cached( $query ) or die
$log-notice($dbh-errstr);
   $sth-execute;
   my $info = $sth-fetchall_arrayref;
   $sth-finish;
   foreach $counter (0 .. $#{$info}) {
  if($info-[$counter][0] == $kat) {
 push @maks_id, $info-[$counter][0];
 print_it($info-[$counter][1]);
  }
   }

   sub print_it {
  my $counter2 = 0;
  my $counter3 = 0;

  foreach $counter2 (0 .. $#{$info}) {
 if($info-[$counter2][0] == $_[0]) {
push @maks_id, $info-[$counter2][0];
foreach $counter3 (0 .. $#{$info}) {
   if($info-[$counter3][0] ==
$info-[$counter2][1]) {
  print_it($info-[$counter3][0]);
   }
}
 }
  }
   }
   my $temp_id = pop @maks_id;
   return $temp_id;
}


Rgds,
Viljo

__
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/



Re: array problem (second try)

2001-09-20 Thread Stas Bekman

 Now
 first time it runs it works just fine, but after that
 array contains only first ID that was pushed there.

the magic match :) Please read:
http://perl.apache.org/guide/porting.html#Sometimes_it_Works_Sometimes_it
http://perl.apache.org/guide/porting.html#Exposing_Apache_Registry_secret


 Oh, and if someone has any good ideas how to
 improve this tree parsing algorithm then i'd be happy
 to hear about it :).

that's the wrong list to discuss parsing algorithms. See 
http://lists.perl.org/


_
Stas Bekman  JAm_pH --   Just Another mod_perl Hacker
http://stason.org/   mod_perl Guide  http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/