From: "Jesús Gabriel y Galán" Date: 2008-09-01T20:15:34+09:00 Subject: Re: Parsing a CSV file column-wise On Mon, Sep 1, 2008 at 1:09 PM, Chris Lowis wrote: > Is there a short-cut to parsing a CSV file column-wise using any of > the available Ruby CSV libraries ? > > For example, at the moment I have: > > require 'csv' > data = "1,2,3\n4,5,6\n7,8,9" > CSV::parse(data) # => [["1", "2", "3"], ["4", "5", "6"], ["7", "8", > "9"]] > > But what I'd like is: > > CSV::parse(data,'columnwise') # => [["1", "4", "7"], ["2", "5", > "8"], ["3", "6", "9"]] > > Perhaps I just need to run the returned array through some kind of > transformation ? Maybe this helps: irb(main):001:0> [["1", "2", "3"], ["4", "5", "6"], ["7", "8", irb(main):002:2* "9"]].transpose => [["1", "4", "7"], ["2", "5", "8"], ["3", "6", "9"]] Jesus.