Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Transposer

by jdporter (Chancellor)
on Jul 13, 2005 at 15:30 UTC ( #474585=note: print w/replies, xml ) Need Help??

in reply to Transposer

You said your motivation was a need to
take a list of tuples and give back the list of all the nth elements of each tuple
but the code you posted doesn't do exactly that. (It transposes a matrix, as already discussed.) So here's code that does exactly that.
# first arg: n # second arg: array(ref) of arrays. # return: list of nth elements. sub nth_elem { map $_->[$_[0]], @{$_[1]} }
Trivial, as you can see.

Replies are listed 'Best First'.
Re^2: Transposer
by Pied (Monk) on Jul 14, 2005 at 06:29 UTC
    Well, it's not a matrix which is input, but it is a matrix that is output. input is a list of strings, with each string defining a tuple, whereas output is a LoL. Anyway, thanks for the code.
      Yeah... but as already discussed, the part that converts those strings into actual arrays should probably be separated from the other part. But hey - if they must be integral, then here:
      # first arg: n # second arg: array(ref) of strings which are comma-separated lists. # return: list of nth elements. sub nth_elemS { map { (split ',')[$_[0]] } @{$_[1]} }

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2023-02-06 09:30 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (33 votes). Check out past polls.