in reply to Creating two dimensional array

use List::Util qw( max ); my @two_dim = map { [ $array1[$_], $array2[$_] ] } 0 .. max( $#array1, $#array2 );

This assumes you have List::Util (a safe assumption). If one array is longer than the other, the "missing" entries will be undef.

Replies are listed 'Best First'.
Re^2: Creating two dimensional array
by doom (Deacon) on Oct 30, 2007 at 22:09 UTC
    Cute use of "max" there.

    I've been getting into "pairwise" lately, myself. From the CPAN module List::MoreUtils:

    use Data::Dumper; use List::MoreUtils qw(pairwise); my @array1 = qw( a b c d e f ); my @array2 = qw( 1 2 3 4 5 6 ); my @matrix = pairwise { [$a, $b] } @array1, @array2; print Dumper(\@matrix), "\n";