BuildLeaf ($leaf_info[0][[$i]],$leaf_info[[1]][[$i]], ...);

This may be just a cut-and-paste problem in posting the OP, but the array indexing used in the example code is doubleplusungood.

An expression like  [1] or  [$i] on its own builds an anonymous array and evaluates as the reference address of the array; this reference address is the only way to access the array, hence "anonymous". A reference address evaluated in numeric context is some (probably rather large) number. The expression  $leaf_info[0][[$i]] evaluates the anonymous array reference returned by  [$i] in the numeric context of an array element index and immediately expands the array  @leaf_info (or to be precise, the anonymous array that is the zeroth element of @leaf_info) to include the indexed array element. (Update: Well, not quite. See Update 2 below.) I doubt this is what you want. E.g.:

c:\@Work\Perl\monks>perl -wMstrict -le "my @ra; ;; $ra[3] = 42; print 'A: elements in array: ', scalar @ra; ;; $ra[[1]] = 99; print 'B: elements in array: ', scalar @ra; " A: elements in array: 4 Use of reference "ARRAY(0x5cc15c)" as array index at -e line 1. B: elements in array: 6078813
The expression  $leaf_info[[1]][[$i]] is horrifically worse | just as bad. (Update: Indeed, it will cause Perl to attempt to build a multi-terabyte array | actually, no; see Update 2 below, another reason for doubting this is the original code.) Note that had you had warnings enabled, Perl would have chided you about these missteps (if, in fact, they exist in the original code).

Update:

BuildLeaf (...,@{@vrf_info[0]},@{@spine_info[[1]]});
This is something else that warnings would have warned you about:  @vrf_info[0] is a single-element array slice and is frowned upon, although it works just fine. We will pass quickly by  @spine_info[[1]] with eyes averted and muttering a brief, earnest prayer.

Update 2: My code example above shows changes to the array produced by write accesses; the OPed code showed pure read accesses, and these produce different effects:

c:\@Work\Perl\monks>perl -wMstrict -le "my @ra; my $x; ;; S($ra[3]); print 'A: elements in array: ', scalar @ra; ;; S($ra[[1]][[0]]); print 'B: elements in top level array: ', scalar @ra; print 'C: elements in 2nd level array: ', scalar @{ $ra[-1] }; ;; sub S { $x = defined($_[0]) . ''; } " A: elements in array: 0 Use of reference "ARRAY(0x94c05c)" as array index at -e line 1. Use of reference "ARRAY(0x432004)" as array index at -e line 1. B: elements in top level array: 9748573 C: elements in 2nd level array: 0
The internal details differ, but the bottom line is the same:  $leaf_info[0][[$i]] et al are not ways in which you ever want to index an array.


Give a man a fish:  <%-{-{-{-<


In reply to Re: Pass Arrays to a subroutine by AnomalousMonk
in thread Pass Arrays to a subroutine by sankoshy

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.