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.:
The expression $leaf_info[[1]][[$i]] isc:\@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
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:
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.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
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |