[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: #help in reading from csv file

Learnatwoa learn@woa.hu

12/7/2006 10:36:00 AM

Here how you can access correctly a csv file. This works and is more in
the ruby style.

require 'csv'

CSV::Reader.parse(File.open('my.csv', 'rb')) do |row|
next if row.first.nil? #skip blank lines
create_product(row)
end

But you can be more restrictive by changing the condition on the next
by:

next unless row.size == 5 #skip all lines without the exact number of
columns (5 here)

I hope this will help you,

++
jerome () {
c = Woa! Kft
w = http://...
}

--
Posted via http://www.ruby-....