From: Stuart Clarke on
Hey all,

Just a quick questions regarding some data I am trying to process. I am
reading a file which contains data like so

HeaderA,HeaderB,HeaderC
1234545,"items, more, random, data",data extradata
1234325,"items, more, data",more stuff
1234125,"items, more, random, data, somethingelse",same
1232135,"stuff, plus, diff, data",data extradata

So it is like CSV, with 3 columns of data one of which is contained
within quotes and has comma's separating the data. I am trying to split
this data into the three columns however I cannot use a comma because it
exists within the second column. I thought maybe I could create like and
index from the header data (HeaderA,HeaderB,HeaderC), but I am unsure.

Can anyone help me get three columns of data into variables?

Thanks a lot
--
Posted via http://www.ruby-forum.com/.

From: arton on
Hi

You may use csv library. It's standard library and came with ruby itself.
http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/index.html

ie)
reuqire 'csv'
a = CSV.open('file', 'r')
a.each do |row1, row2, row3|
...
end

regards

--
arton <artonx(a)yahoo.co.jp>

--------------------------------------
2010 FIFA World Cup News [Yahoo!Sports/sportsnavi]
http://pr.mail.yahoo.co.jp/southafrica2010/

From: Stuart Clarke on
Good point.

Thanks a lot

arton wrote:
> Hi
>
> You may use csv library. It's standard library and came with ruby
> itself.
> http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/index.html
>
> ie)
> reuqire 'csv'
> a = CSV.open('file', 'r')
> a.each do |row1, row2, row3|
> ...
> end
>
> regards
>
> --
> arton <artonx(a)yahoo.co.jp>

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