On Mar 17, 2006, at 11:38 AM, Geoff wrote:

> Cool, the puts command works, but when I tweak it to output this to a
> file...

If you go back and look at my last message, I used the puts version  
to create a file (using redirection).  That's a pretty flexible  
trick, probably worth getting the hang of.

The main problem with your new version is that you are using CSV to  
manage the output file, but it order to enforce quoting we had to  
roll our own solution (the CSV file format does not require it for  
the examples you are showing).  Switching to a normal file should get  
you going:

#!/usr/local/bin/ruby -w

require "csv"
require "enumerator"

last_row = Array.new

File.open("C:\\temp\\geoff\\filldown\\filldownNew.txt", "w") do | 
out_file|
   CSV.foreach("C:\\temp\\geoff\\filldown\\filldown.txt") do |row|
     out_file.puts( row.enum_for(:each_with_index).map do |cell, index|
       if cell.empty?
         last_row[index]
       else
         last_row[index] = cell
       end
     end.map { |output| "\"#{output}\""}.join(",") )
   end
end

Hope that helps.

James Edward Gray II