http://qs321.pair.com?node_id=643801


in reply to Re^2: How to swap rows with columns?
in thread How to swap rows with columns?

That doesn't do what my code does at all, which is to avoid the need to fix the array by transposing it by creating it right in the first place. From the point of view, your code is a step backwards. If you wanted to change my code to avoid pushing, then you'd do

my @data; while (<>) { my @fields = split ' '; my $col = $. - 1; for my $row (0..$#fields) { $data[$row][$col] = $fields[$row]; } }

Tested.

Replies are listed 'Best First'.
Re^4: How to swap rows with columns?
by jdporter (Paladin) on Oct 10, 2007 at 04:39 UTC
    That doesn't do what my code does at all.

    Maybe not, but it does what the OP requested, namely, transpose a 2-d array.