http://qs1969.pair.com?node_id=11125225


in reply to List into two-dimensional array

You could use an on-the-fly subroutine. Probably not a good approach if the arrays are large.

johngg@abouriou:~$ perl -Mstrict -Mwarnings -MData::Dumper -E ' my @list = qw{ 1 2 3 4 5 6 7 8 9 10 11 12 }; my( $nCols, $nRows ) = ( 4, 3 ); my @AoA = sub { my @tAoA; push @tAoA, [ splice @_, 0, $nCols ] while @_; return @tAoA; }->( @list ); print Data::Dumper->Dumpxs( [ \ @list, \ @AoA ], [ qw{ *list *AoA } ] +);' @list = ( '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12' ); @AoA = ( [ '1', '2', '3', '4' ], [ '5', '6', '7', '8' ], [ '9', '10', '11', '12' ] );

I hope this is of interest.

Cheers,

JohnGG