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.
In reply to Re^3: How to swap rows with columns?
by ikegami
in thread How to swap rows with columns?
by perl_geek
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |