| 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.
| |