Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: How to swap rows with columns?

by ikegami (Pope)
on Oct 09, 2007 at 21:05 UTC ( #643801=note: print w/replies, xml ) Need Help??


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 (Canon) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://643801]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2021-10-20 10:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (79 votes). Check out past polls.

    Notices?