Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread
Message: 90105
BY: James Gray (bbazzarrakk)
DATE: 2009-09-04 19:22
SUBJECT: RE: Row preprocessing ?

 

Luckily, handling the headers is very easy in your case. For example:

data = <<END_DATA
a:b:c
1:2:3
4:5:6
END_DATA

headers = nil
data.each do |row|
row.strip!
if headers.nil?
headers = row.split(":")
else
fields = Hash[*headers.zip(row.split(":")).flatten]
p fields
end
end

I'm not trying to run you off, of course. It's just that you are feeding non-CSV data to a CSV parser. It's not too surprising this is problematic. Your data is very easy to read without help though.

I hope that makes sense.


Thread View

Thread Author Date
Row preprocessing ?Thibaut Barrère2009-09-04 18:52
      RE: Row preprocessing ?James Gray2009-09-04 19:01
            RE: Row preprocessing ?Thibaut Barrère2009-09-04 19:09
                  RE: Row preprocessing ?James Gray2009-09-04 19:22
                        RE: Row preprocessing ?Thibaut Barrère2009-09-04 19:28

Post a followup to this message