Hello Bill, Thank you for your quick reply. And Thank you once again, as your suggestion works great.
I may have to work on how to deal with invalid lines in the CSV file in the future. But this works for the moment. Thank you Margam On Jan 8, 3:16 pm, "Bill Agee" <billa...@gmail.com> wrote: > The csv module 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 > the CSV::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 an CSV file 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 the CSV file and store in variables. CSV file is in the > > same folder as the script > > d = DataHandler.new("gmail.csv") > > > $dataarray=[] #Creating an empty array > > > #storing each value from the CSV file to the array elements. Note: > > "Value" is the header of the second column in the CSV file. > > $dataarray[0]=d.data[0].Value > > $dataarray[1]=d.data[1].Value > > $dataarray[2]=d.data[2].Value > > $dataarray[3]=d.data[3].Value > > ... > > > #rest of script, where the array element are used. > > ------------------- > > The above approach works. But I don't want to manually enter each > > value from the file into each array element. > > Is there an easier and better (shorter) way to achieve this? > > > Please help. > > Thank you > > Margam --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Watir General" group. To post to this group, send email to watir-general@googlegroups.com Before posting, please read the following guidelines: http://wiki.openqa.org/display/WTR/Support To unsubscribe from this group, send email to watir-general-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/watir-general -~----------~----~----~----~------~----~------~--~---