Heffstar has asked for the wisdom of the Perl Monks concerning the following question:
Good Afternoon Monks,
After beating my head against my screen for a little while, I figured I'd ask those who know significantly more than me.
I've created a recursive subroutine that provides me with some results (according to the warn commands, I'm getting what I'm looking for) but the issue is that my storage array is empty when it's finished. I'm sure it's something "simple", but I can't seem to figure it out. Here's the code:
my @level; &myfunc($number, $company, \@level, 0, $dbh); print $#level; # prints -1 sub myfunc { my ($manager_no, $company_id, $level_ref, $index, $dbh) = @_; my ($employee_no, $emp_company_id); my ($sql, $sth); my @level = @$level_ref; $sql = 'query'; $sth = $dbh->prepare($sql); if ( !($sth->execute($manager_no, $company_id)) ) { die; } while ( ($employee_no, $emp_company_id) = $sth->fetchrow_array() ) + { if ( exists $level[$index]{"$employee_no-$emp_company_id"} ) { $level[$index]{"$employee_no-$emp_company_id"} = 1; } else { if ( ( $employee_no eq $manager_no) && ($emp_company_id eq $co +mpany_id) ) { # do nothing } else { $level[$index]{"$employee_no-$emp_company_id"} = "$manager_no- +$company_id"; &myfunc($employee_no, $emp_company_id, $level_ref, $index + 1, + $dbh); } } } }
If someone has a suggestion, I'd be very happy to hear it.
Thanks and all the best!
Hugh
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Recursion - Array of Hashes
by toolic (Bishop) on Feb 02, 2010 at 19:14 UTC | |
|
Re: Recursion - Array of Hashes
by ikegami (Patriarch) on Feb 02, 2010 at 19:16 UTC | |
by Heffstar (Acolyte) on Feb 02, 2010 at 20:19 UTC | |
|
Re: Recursion - Array of Hashes
by crashtest (Curate) on Feb 02, 2010 at 19:28 UTC | |
by Heffstar (Acolyte) on Feb 02, 2010 at 20:22 UTC | |
by Heffstar (Acolyte) on Feb 02, 2010 at 21:17 UTC |