in reply to Creating two dimensional array

The following will do the trick:
my @matrix = (\@array1, \@array2);

It can be accessed using

$matrix[$col][$row]

Replies are listed 'Best First'.
Re^2: Creating two dimensional array
by KurtSchwind (Chaplain) on Oct 31, 2007 at 00:11 UTC
    This is what I wanted to post, but I was thinking that maybe I had misunderstood the question. I use this exact thing to 'concat' cols together into a "2 dim array".
    --
    I used to drive a Heisenbergmobile, but everyone I looked at the speedometer, I got lost.
Re^2: Creating two dimensional array
by doom (Deacon) on Oct 30, 2007 at 22:23 UTC
    I think you just answered a slightly different question. Most of us have interpreted the goal like this:
    $VAR1 = [ [ 'a', '1' ], [ 'b', '2' ], [ 'c', '3' ] ];
    Your solution looks like this:
    $VAR1 = [ [ 'a', 'b', 'c' ], [ '1', '2', '3' ] ];

      Most of us have interpreted the goal like this

      Yes, I noticed. It would have been silly to post something that was already posted.

      There's no rule that says that the first dimension must be rows and the second must be columns. Here code that shows my solution does indeed use @array1 as the first column and @array2 as the second column.

      my @array1 = qw( a b c ); my @array2 = qw( X Y Z ); my @matrix = (\@array1, \@array2); for my $row (0..$#{$matrix[0]}) { for my $col (0..$#matrix) { print $matrix[$col][$row], "\t"; } print "\n"; }
      a X b Y c Z

      Update: Added code.

        There's no rule that says that the first dimension must be rows and the second must be columns.

        True, but myself I tend to prefer the array of two-valued arrays structure myself. I think of the inner arrays as "points", i.e. pairs of (x,y) values, and typically you want to do things like push/pop points from your collection of data.

        But then it all depends on how the original poster is going to be graded -- I mean, on the details of the OP's application.