fastercsv: row["header1"] syntax doesn't work, why?

B

bbxx789_05ss

$ cat data.csv
name number
me 12
you 20



require 'rubygems'
require 'fastercsv'

FasterCSV.foreach("data.csv", :headers =>true, :col_sep =>'\t') do |row|
puts row
puts row['name']
puts row['number']
puts row.class
end

--output:--
me 12
nil
nil
FasterCSV::Row
you 20
nil
nil
FasterCSV::Row


I've sifted through the docs, and I can't find any indication why the
row['name'] syntax won't work.
 
B

bbxx789_05ss

7stud said:
$ cat data.csv
name number
me 12
you 20

I've sifted through the docs, and I can't find any indication why the
row['name'] syntax won't work.

Arrrgh. vim was turning my tabs into spaces, so the '\t' separator
wasn't in the data.csv file. This works:

$ cat data.csv
name,number
me,12
you,20

-------

FasterCSV.foreach("data.csv", :headers =>true) do |row|
puts row
puts row['name']
puts row['number']
puts row.class
end

--output:--
me,12
me
12
FasterCSV::Row
you,20
you
20
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top