From: Brian Candler Date: 2009-02-11T23:35:04+09:00 Subject: Re: Problem writing a Faster_csv generated record to a file thiel wrote: > This is the code: Only part of it - you haven't shown what sort of object custrecord is, for example. > op = File.new("C:/Test/testmap.csv", "w") > for i in 0 .. n > for j in 0 .. 12 > custrecord[j] = x[i,j] > end STDERR.puts "custrecord = #{custrecord.inspect}" > csv_string = FasterCSV.generate_line(custrecord) > csv_string.chop! > csv_string.gsub!(/,/, ';') > op.puts csv_string > end > > The result in folder Test is: testmap.csv --> 0Kb!! (Type CSV file) That STDERR line will tell you whether custrecord contains what you expect. If not, work backwards until you find the problem (e.g. look at what's in x) There are simpler ways to drive fastercsv than your code though. Try this: require 'rubygems' require 'fastercsv' FasterCSV.open("/tmp/test.csv", "w", :col_sep=>";") do |csv| custrecord = ["foo","bar","baz"] csv << custrecord end The documentation for fastercsv is within the code, which may be installed somewhere like .../gems/fastercsv-1.4.0/lib/faster_csv.rb on your system. Or type "gem server --daemon" then point your web browser at http://localhost:8808/ -- Posted via http://www.ruby-forum.com/.