Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Transposer

by jdporter (Canon)
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2020-09-23 13:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (131 votes). Check out past polls.

    Notices?