Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Transpose a bi-dimensional array

by dbwiz (Curate)
on Jul 21, 2003 at 11:24 UTC ( [id://276222]=note: print w/replies, xml ) Need Help??


in reply to Transpose a bi-dimensional array

tye has written a tool that should serve your purpose. Have a look at mapcar

use mapcar; my @matrix = ( [ qw(ab cd ef gh)], [ qw(ij kl mn op)], [ qw(qr st uv wx)] ); my @transposed = mapcar {[@_]} @matrix; print join( " ", @$_), $/ for @transposed; __END__ ab ij qr cd kl st ef mn uv gh op wx
Update
mapcar is now a function in tye's Algorithm::Loops.

The above example would becpme:

use Algorithm::Loops qw(MapCar); my @matrix = ( [ qw(ab cd ef gh)], [ qw(ij kl mn op)], [ qw(qr st uv wx)] ); my @transposed = MapCar {[@_]} @matrix; print join( " ", @$_), $/ for @transposed;

With exactly the same result.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-16 09:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found