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.