This is not my exact script, but I wrote it in a similar format. Trying to create an array of arrays in one subroutine, and then returning it as a variable, to be used later in a second subroutine. When I test by printing indices from the arrays in the array of arrays, however, it does not seem to work (it says, for instance, "Use of uninitialized value $array1[0] in concatenation (.) or string"].
my @array1; my @array2; my @array3; my @array_array; @array_array = @{ &firstRoutine() }; &secondRoutine(\@array_array ); sub firstRoutine{ my $count = 0; while (<INPUT>){ my @line = split( /\s+/, $_ ); $array1[$count] = $line[0]; $array2[$count] = $line[1]; $array3[$count] = $line[2]; $count = $count + 1; } my @array_array; push( @array_array, @array1, @array2, @array3); return \@array_array; } sub secondRoutine { my (@array1, @array2, @array3) = { shift @_ }; print ("Test first value in array1: $array1[0]"); print ("Test third value in array2: $array2[2]"); print ("Test fifth value in array3: $array3[4]"); }
In reply to Array of arrays by SuzuBell
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |