in reply to Transpose a bi-dimensional array

Or, you could just peek in the source of Math::Matrix, nick the transpose() method, un-OO-ify it, and ... voila!

#!perl -l my @matrix = ( [ qw(ab cd ef gh)], [ qw(ij kl mn op)], [ qw(qr st uv wx)] ); my $transposed = transpose(\@matrix); local $" = ","; print "@$_" for @$transposed; sub transpose { my $matrix = shift; my @result; my $m; for my $col (@{$matrix->[0]}) { push @result, []; } for my $row (@{$matrix}) { $m=0; for my $col (@{$row}) { push(@{$result[$m++]}, $col); } } return \@result; }

Disclaimer: not my coding style! I just modified existing code to make a point (Use the Source, Luke)

--
3dan