Prev: Net::SCP download from windows to linux and encrypt password
Next: Multi-cpu and ruby Threading
From: Stuart Clarke on 29 Jun 2010 07:41 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 29 Jun 2010 08:13 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 29 Jun 2010 08:21 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/.
|
Pages: 1 Prev: Net::SCP download from windows to linux and encrypt password Next: Multi-cpu and ruby Threading |