From: "drubdrub@..." Date: 2007-06-30T05:20:06+09:00 Subject: Re: Newbie: fastcsv: Read rows, print rows Thanks for such a rapid, patient response! You certainly helped me get "unstuck". Appreciate the references. I had found the doc pages but was still laboring. For the record, here is my working code. No rocket science, but may be useful to someone. All the best! require 'rubygems' require 'fastercsv' infile = "infile2.csv" FasterCSV.open(infile, "r") do |row| row.each{|row| puts "row: #{row.inspect}"} end ---------------------------------- On Jun 29, 12:06 pm, James Edward Gray II wrote: > On Jun 29, 2007, at 1:50 PM, drubd...@gmail.com wrote: > > > New to Ruby. It probably shows. > > Welcome to Ruby! > > > Trying to accomplish some simple initial tasks, and study. > > > Objectives > > 1. Read rows from a CSV file > > 2. Write rows to STDOUT > > > A cat() equivalent. > > > I've been looking but don't find it. Are there any good tutorials on > > using fastcsv? This might be a good candidate for such. > > There's the documentation: > > http://fastercsv.rubyforge.org/ > > You'll find basic reading and writing information on this page in > particular: > > http://fastercsv.rubyforge.org/classes/FasterCSV.html > > There are also some examples in the source: > > http://viewvc.rubyforge.mmmultiworks.com/cgi/viewvc.cgi/trunk/ > examples/?root=fastercsv > > > require > > 'fastercsv' > > The above should be on one line. You may also need to add a: > > require 'rubygems' > > before requiring FasterCSV, depending on your environment. > > > fastercsv.open("rfile2", "r") do |csv| > > There is an error is on the line above, which needs to be: > > FasterCSV.open... > > > csvData.each{|row| puts "row: ${row}"} > > Change csvData to csv in the line above. Also replace ${row} with # > {row.inspect}. > > > end > > That should get you running. > > You can do this a little easier using foreach(): > > FCSV.foreach("rfile2") do |row| > p row > end > > Hope that helps. > > James Edward Gray II