Hello Bill,
So I was trying to get data starting from a particular row (instead
of from the first row) and have not been very successful.
Say I want to start getting data from Row 2 and as before Column 2.
I tried the following, but did not work:
CSV::Reader.parse(File.open('gmail.csv')) { |row| array << [1][1] }
CSV::Reader.parse(File.open('gmail.csv')) { |row| array << ['r1c1'] }
Can you help me? How should I be specifying the row and columns to be
saved in the array?
Thank you very much.
> Thecsvmodule should be able to do what you need, without much fuss:
>
> require 'csv'
> array = []CSV::Reader.parse(File.open('foo.csv')) { |row| array << row[1] }
>
> That snippet will open 'foo.csv', and for each row, push the second
> column's value onto the array. Note that if you need to deal with
> lines that are commented, empty, or otherwise invalid, a little more
> work would be needed to handle those situations.
>
> More info:
>
>
http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/index.html(Click on
> theCSV::Reader class for applicable docs)
>
> On Thu, Jan 8, 2009 at 2:48 PM, Margam <
nk.mar...@gmail.com> wrote:
>
> > Hello all,
> > I am trying to get data from a particular column (second in my case)
> > of anCSVfile and store it into an array. And then use the array
> > elements within my script
> > Curerntly my script(below) uses the "datahandler.rb"
> > ---------------
> > require 'watir'
> > require 'watir/datahandler'
> > require "test/unit"
>
> > #Get Data from theCSVfile and store in variables.CSVfile is in the
> > same folder as the script
> > d = DataHandler.new("gmail.csv")
>
> > $dataarray=[] #Creating an empty array
>
> > #storing each value from theCSVfile to the array elements. Note: