Please quote properly, and attribute your quotations.
Quoth gamo <
ga...@telecable.es>:
> [I wrote:]
>> for my $r (0..$#old) {
>> my $row = $old[$r];
>> for my $c (0..$#$row) {
>> $new[$c][$r] = $$row[$c];
>> }
>> }
>>
>> I'm not sure it's possible to do that any more elegantly, given that you
>> can't take a slice vertically through a 2d array.
>
> Well, that does a tansposition,
Yes. You asked how to interchange rows and columns; that's what a
transposition does.
> and after that is posible to do the
> column swap:
>
> my @xy = @new;
>
> for $y (0,1){
> ($xy[0][$y],$xy[1][$y]) = ($xy[1][$y],$xy[0][$y]);
> }
>
> and redo the transposition. Or directly,
>
> for $x (0,1){
> ($xy[$x][0],$xy[$x][1]) = ($xy[$x][1],$xy[$x][0]);
> }
So you're actually trying to exchange two columns. Yes, that is the way
to do it. For the more general case of reversing the columns of a NxM
matrix, you want
for my $r (@matrix) {
splice @$r, 0, $#r, reverse @$r;
}
You should look on CPAN: a lot of this sort of basic stuff has already
been implemented.
Ben