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

Discussion in 'Ruby' started by bbxx789_05ss@yahoo.com, Nov 5, 2007.

  1. Guest

    $ 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/.
     
    , Nov 5, 2007
    #1
    1. Advertising

  2. Guest

    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/.
     
    , Nov 5, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    938
    Mark Rae
    Dec 21, 2006
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,137
    Smokey Grindel
    Dec 2, 2006
  3. D
    Replies:
    0
    Views:
    239
  4. Li Chen

    fastercsv and several row

    Li Chen, Jul 22, 2008, in forum: Ruby
    Replies:
    4
    Views:
    89
    Li Chen
    Jul 22, 2008
  5. John Mcleod
    Replies:
    6
    Views:
    190
    John Mcleod
    Feb 2, 2010
Loading...

Share This Page