Margam, This is all to do with the basics of Ruby. It would be well worth working through some of the ruby tutorials.
In this case; hash[] On 14 Jan 2009, at 01:19, Margam <nk.mar...@gmail.com> wrote: > > Follow Up > Hello All, > After googling for some time, I found an easy way to get the data into > an Hash. Thanks to One Mr.Ryan. > --------------------- > hash = {} > CSV.foreach('test.csv') do |row| > hash[row[0]] = row[1] > end > ----------------- > > But I have some questions regarding accessing the values using the Key > field. > Based on the CSV file example I had mentioned in my previous entry: > 1. When I do: > $browser.goto(hash[URL]) > I get a error: > -------------- > NameError: uninitialized constant TestSuite::URL > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/ > active_support/dependencies.rb:493:in `const_missing' > csvdriven.rb:102:in `test00_gmail' > -------------- > But works fine when I do: $browser.goto(hash['URL']). > Why are the single quotes required? > > 2. When I try to output the values using the KEys like this: > puts hash['URL'] > the output looks like this: "http://gamil.com" > Why does the output has the double quotes? > > Hope my questions are clear. Thank you. > > Margam > > On Jan 13, 3:58 pm, Margam <nk.mar...@gmail.com> wrote: >> Hello All, >> I have been recently learning to use both the CSV module and the >> FasterCSV gem to create an array from a CSV file. >> Say my CSV file(file.csv) looks like this (first row is the header, >> not used in script): >> Parameter,Value >> URL,http://gamil.com >> Login,mylogin >> Password,mypassword >> >> My script using the CSV module is: >> require 'csv' >> array=[] >> CSV::Reader.parse(File.open("file.csv")){|row| array << row[1]} >> >> The above code saves the Values in column two into an array. I use >> the >> array elements in my script. >> >> IN the same way, is there a method to create a Hash table. I would >> like to access the values in column 2 using the Key on column 1. I >> want to do this, as the CSV file may keep changing. >> Also how to access the Hash keys(or use them in the script)? >> >> Kindly provide guidance. >> 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 -~----------~----~----~----~------~----~------~--~---