[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

CSV question

Shai Rosenfeld

10/16/2007 2:22:00 PM

hi,

CSV (more specifically FasterCSV) reads the file i provided row by row

FasterCSV.foreach('path/to/file.csv', 'r') do |r|
r # this is an array of a row in the file
end

but i need to get the array column by column..
is there a way i can simply do this? (even rotating the excel 90 degrees
should do the trick as well!)

FasterCSV.foreachcolumn('path/to/file.csv', 'r') do |c|
c # this is an array of a column yay for all and such things
end

apologize for the redundant question
--
Posted via http://www.ruby-....

2 Answers

Shai Rosenfeld

10/16/2007 2:32:00 PM

0

sorry, ignore this post
--
Posted via http://www.ruby-....

Jesús Gabriel y Galán

10/16/2007 2:35:00 PM

0

On 10/16/07, Shai Rosenfeld <shaiguitar@gmail.com> wrote:
> CSV (more specifically FasterCSV) reads the file i provided row by row
>
> FasterCSV.foreach('path/to/file.csv', 'r') do |r|
> r # this is an array of a row in the file
> end
>
> but i need to get the array column by column..
> is there a way i can simply do this? (even rotating the excel 90 degrees
> should do the trick as well!)

I don't know if there's a better way, but you can do this:

a = FasterCSV.parse(File.read("catalogue.csv"))
a.transpose.each {|column| ...}

but you will have errors if the rows don't have the same number of elements.

Hope this helps,

Jesus.