Hi, I am a newbie and I want to export an excel-file using fastcsv. This is an example program from book Practical Ruby Gems: ================#!/usr/local/bin/ruby -w #fastercsv.rb # # Created by James Edward Gray II on 2006-04-01. # Copyright 2006 Gray Productions. All rights reserved. # # This file is just another name for faster_csv.rb. require "faster_csv" csvdata = "jones,bob,165\n" csvdata = "smith,tim,10\n" csvdata = "doe,john,155\n" lastname, firstname, iq = "" fastercsv.parse(csvdata) do |row | lastname, firstname, iq = *row puts "#{firstname} #{lastname} has an IQ of #{iq}" end ================== I am using Netbeans and I got the following message: C:/NetBeansProjects/Fastercsv/lib/main.rb:17: undefined local variable or method `fastercsv'' for main:Object (NameError) Can you suggest how to solve this problem? Thanks in andvance, Thiel --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
My results aren''t much better :( thufir@arrakis ~/csv $ thufir@arrakis ~/csv $ ruby import.rb import.rb:9: undefined local variable or method `fastercsv'' for main:Object (NameError) thufir@arrakis ~/csv $ thufir@arrakis ~/csv $ cat import.rb require ''fastercsv'' csvdata = "one\n" csvdata = "two\n" csvdata = "three\n" one = "" fastercsv.parse(csvdata) do |row | one = *row end thufir@arrakis ~/csv $ thufir@arrakis ~/csv $ mysql -u root -ppassword Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 5.0.44-log Gentoo Linux mysql-5.0.44 Type ''help;'' or ''\h'' for help. Type ''\c'' to clear the buffer. mysql> DESCRIBE csv_data.one; +-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | one | int(11) | YES | | NULL | | +-------+---------+------+-----+---------+-------+ 1 row in set (0.26 sec) mysql> quit Bye thufir@arrakis ~/csv $ -Thufir --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The following runs without error and generates output :) However, it doesn''t import data to the db yet :( RTFM at: http://fastercsv.rubyforge.org/classes/FasterCSV.html the code, data and db: thufir@arrakis ~/csv $ thufir@arrakis ~/csv $ ruby import.rb ["one"] ["two"] ["three"] thufir@arrakis ~/csv $ thufir@arrakis ~/csv $ cat import.rb require ''rubygems'' require ''fastercsv'' infile = "data.csv" FCSV.foreach(infile) do |row| p row end thufir@arrakis ~/csv $ thufir@arrakis ~/csv $ sqlite3 foo.sqlite3 SQLite version 3.4.1 Enter ".help" for instructions sqlite> .schema CREATE TABLE foos (bar STRING); CREATE TABLE schema_info (version integer); sqlite> sqlite> SELECT * FROM foos; sqlite> .quit thufir@arrakis ~/csv $ -Thufir --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---