Csv to hash

ou_ryperd said:

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

Ruby comes with a CSV library:

require 'csv'
hash = {}
CSV.foreach('test.csv') do |row|
  hash[row[0]] = row[1]
end
p hash

Ryan