From: James Edward Gray II Date: 2006-12-27T00:30:33+09:00 Subject: Re: Parsing a CSV file having multiple records in RUBYp On Dec 26, 2006, at 3:15 AM, come wrote: > Since your file has a header, you could write something like : Obviously I am biased, but I sure think FasterCSV makes this kind of thing easier: >> require "rubygems" => false >> require "faster_csv" => true >> csv = < "item,in_stock,reorder_limit\n"Real ""Rubies""",10,5\nPearls,100,20 \nSnakes,2,5\n" >> result = FCSV.parse(csv, :headers => true, :header_converters => :symbol) => #, #, #] >> puts re readline require__ result readlines require_gem retry redo require_gem_with_options return remove_instance_variable rescue require respond_to? >> puts result.map { |row| row[:item] } Real "Rubies" Pearls Snakes => nil >> result.each { |row| p row.to_hash } {:in_stock=>"10", :reorder_limit=>"5", :item=>"Real \"Rubies\""} {:in_stock=>"100", :reorder_limit=>"20", :item=>"Pearls"} {:in_stock=>"2", :reorder_limit=>"5", :item=>"Snakes"} => #, #, #] James Edward Gray II