array of arrays to file

J

Junkone

i want to use faster csv to write a array of arrays to file. But i am
little stuck on how do do it.
require 'fastercsv'
arr=[[1,2],[2,3]]
arr.each { row|
FasterCSV.open("c:\\temp\\one.csv", "w")
do |csv|

csv<<row
end
}
end
 
B

Brian Candler

So, what happened when you ran your script? What did it do?

I reckon you have it inside-out, because you're re-opening the CSV file
for each row of the array, which will erase the file.

I think you should open the CSV file once, and then write each row.

require 'rubygems'
require 'fastercsv'
arr=[[1,2],[2,3]]
FasterCSV.open("temp.csv", "w") do |csv|
arr.each do |row|
csv << row
end
end
 
J

Junkone

So, what happened when you ran your script? What did it do?

I reckon you have it inside-out, because you're re-opening the CSV file
for each row of the array, which will erase the file.

I think you should open the CSV file once, and then write each row.

require 'rubygems'
require 'fastercsv'
arr=[[1,2],[2,3]]
FasterCSV.open("temp.csv", "w") do |csv|
  arr.each do |row|
    csv << row
  end
end

you are right. thanks.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top