Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > fastercsv: row["header1"] syntax doesn't work, why?

Reply
Thread Tools

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

 
 
bbxx789_05ss@yahoo.com
Guest
Posts: n/a
 
      11-05-2007
$ 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.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
bbxx789_05ss@yahoo.com
Guest
Posts: n/a
 
      11-05-2007
7stud -- wrote:
> $ 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
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax Checker that's better than the normal syntax checker Jacob Grover Ruby 5 07-18-2008 05:07 AM
Syntax error? What syntax error? Assignment fo default values? Mark Richards Perl Misc 3 11-18-2007 05:01 PM
Syntax bug, in 1.8.5? return not (some expr) <-- syntax error vsreturn (not (some expr)) <-- fine Good Night Moon Ruby 9 07-25-2007 04:51 PM
[ANN] SqlStatement 1.0.0 - hide the syntax of SQL behind familiarruby syntax Ken Bloom Ruby 3 10-09-2006 06:46 PM
Syntax highligth with textile: Syntax+RedCloth ? gabriele renzi Ruby 2 12-31-2005 02:44 AM



Advertisments