in reply to Re^2: Creating two dimensional array
in thread Creating two dimensional array

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.

Replies are listed 'Best First'.
Re^4: Creating two dimensional array
by doom (Deacon) on Oct 31, 2007 at 08:34 UTC
    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.