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. Advertisements

  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. Advertisements

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. David Prowak

    Why oh why doesn't my data view work?

    David Prowak, Jan 30, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    916
    Alvin Bruney [MVP]
    Jan 30, 2004
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    1,369
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,837
    Smokey Grindel
    Dec 2, 2006
  4. D
    Replies:
    0
    Views:
    499
  5. Li Chen

    fastercsv and several row

    Li Chen, Jul 22, 2008, in forum: Ruby
    Replies:
    4
    Views:
    135
    Li Chen
    Jul 22, 2008
  6. John Mcleod
    Replies:
    6
    Views:
    241
    John Mcleod
    Feb 2, 2010
  7. Sara
    Replies:
    6
    Views:
    486
    John W. Krahn
    Apr 12, 2004
  8. PerlFAQ Server
    Replies:
    0
    Views:
    453
    PerlFAQ Server
    Apr 26, 2011
Loading...