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


In reply to Recursion - Array of Hashes by Heffstar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.