Transposing a two dimensional array using perl

sub makeTransposed {
my $a=shift;
my @rows=@{$a};
my @transposed = ();
for my $row (@rows) {
for my $column (0 .. $#{$row}) {
push(@{$transposed[$column]}, $row->[$column]);
}
}
return \@transposed;
}

First get the reference of the two dimensional array and then create and setup the transposed array.

廣告