Just briefly scanning your code, it looks like you're working with a new array in your subroutine instead of the array reference you passed into it. When you do this:

my @level = @$level_ref;
... you've essentially taken a copy of the array that $level_ref was pointing to. Then whenever you assign via $level[$index], you're working with the copy that's scoped to your subroutine - and not with the original @level that's scoped for the entire script.

There are two ways you could approach this. One way is to continue down the path you're trying to get on, and using $level_ref in your subroutine. In a nutshell, you'd replace code that was working with the subroutine scoped @level with code that uses the passed-in array reference $level_ref:

$level[$index]{"$employee_no-$emp_company_id"} = 1; # ... becomes ... $level_ref->[$index]{"$employee_no-$emp_company_id"} = 1;

Another way to solve the issue is to just work directly with the script-scoped @level, and forget about passing the reference around. This isn't exactly clean (it's the "global variable" approach), but hey, if it gets the job done... all you'd have to do is remove the line that declares @level within the subroutine:

my @level = @$level_ref; # delete this!

Hope this helps.


In reply to Re: Recursion - Array of Hashes by crashtest
in thread 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.