One dimensional array to two with Perl

my $array2D=&make2D(\@array1D);

sub make2D {
my $a=shift;
my @array1D=@{$a};
my $maxrow=11;
my $maxcol=21;
my @matrix=();
for(my $i=0;$i<$maxrow;$i++){
@r=splice @array1D,0,$maxcol;
push @{$matrix[$i]},@r;
}
return \@matrix;
}

Using perl splice command extract the array one after another. One dimensional array will be chopped into two dimensional array now.

廣告