in reply to Question about array reference

push @{ $results[$j][$z] }, \@result_1.";"\@result_2;

The line above from your code has a syntax error, so it's hard to tell exactly what you're trying to do. Based on the results you're getting, I'd guess your actual code had another . after the second double quote. So it's taking references to the two arrays and concatenating them together as strings with a semi-colon between them, and then pushing them onto the array pointed to by $results[$j][$z]. But treating an array reference like a string returns a value like ARRAY(0x244dd58) corresponding to the memory location of the array, not the contents of the array, which are probably what you want.

So you could do this a couple different ways. You could put the two arrays together, and save a single reference to the resulting array. Or you could save a reference to an array containing two references to your two arrays, which is probably what you want, assuming you want to be able to tell later where test1.ksh stopped and test2.ksh started.

The other issue is that push doesn't really make sense here. Your looping with $j and $z guarantees that you're only going to push onto each sub-sub-array once. So that third level of arrays isn't necessary. Just save a reference to your results in $results[$j][$z]. Using the two methods mentioned above:

#save a reference to a single array containing the lines from both sub +-processes: $results[$j][$z] = [ @result_1, @result_2 ]; print $results[$j][$z][0]; # print the first line of the total output # # or # # save a reference to an array containing references to two arrays eac +h containing the output of one sub-process: $results[$j][$z] = [ \@result_1, \@result_2 ]; print $results[$j][$z][0][0]; #print the first line from test1.ksh print $results[$j][$z][1][0]; #print the first line from test2.ksh

Aaron B.
My Woefully Neglected Blog, where I occasionally mention Perl.

Replies are listed 'Best First'.
Re^2: Question about array reference
by Pazzeo (Initiate) on Dec 04, 2011 at 15:58 UTC

    Thank you very much Aaron

    Yes, during the copying in paste I forgot/delete the last . after the ";". I wanted to put the reference of the arrays in one unique array.

    So in the end, your code, did what I want :)

     $results[$j][$z] = [ \@result_1, \@result_2 ];

    Thank you very much

    Pazzeo