Hi - I'm fairly new to ruby and trying to read a csv file using the
fastercsv gem. I managed to read the rows arrays of data using:
require 'fastercsv'
def read_csv
path_to_file = "/home/work/some_file.csv"
# open the csv file to read
csv = FasterCSV.open(path_to_file, "r")
# do stuff on rows as arrays
while row = csv.readline
#... row will be ["cell1", "cell2", "cell3", ...]
end
end
What I'm trying to understand is how do I get the row as a hash where
the keys are the column headers (so I don't have to remember where each
column sits in the array):
#...inside loop
col1 = row['some column']
col2 = row['another column']
#...
I'm sure there's a way to do this, but the RDoc wasn't much help. I'd
appreciate any tips - thanks!
···
--
Posted via http://www.ruby-forum.com/.