maybe this will help - it uses the first line in the csv as the handle  
to access the data e.g. -

myname,myage
kingsley,29
dave,28

d = Datahandler.new("data.csv")
d.data[0].myname  # returns kingsley
d.data[1].myage   # returns 28 (daves age)

class DataHandler

	# This allows you to put data in a csv file and access it in  
your scripts for
	# a data driven approach.
	#
	# e.g.
	# require 'datahandler'
	# d = DataHandler.new("data.csv")
	# loginId = d.data[0].LoginId		--> line 1 of the csv  
file and column LoginId
	# pin = d.data[0].Pin				--> line 1 of  
the cvs file and column Pin
	#
	def initialize(datafile)
		@datafile = datafile
	end
	 
	def data
		csv_data = File.readlines(@datafile)
		header = csv_data[0].split(",")
		header.each{|z| z.chomp!}
		data = Struct.new("Data", *header)
		csv_data.shift
		data_array = []
		csv_data.each do |line|
			line.each{|z| line.chomp!}
			data_array << data.new(*line.split(","))
		end
	return data_array
	end
	 
end




On 02/08/05 09:56:04, ou_ryperd wrote:
> Hi
> I have a csv file with two fields per line. What would the most
> effective way be to read it into a hash variable ? e.g.:
> 10000,A
> 10001,B
> 10002,C
> 
> I have searched ruby-talk and comp.lang.ruby and did not find a
> suitable example.
> thanks in advance
> 
> 
> 
>