From: gregarican Date: 2006-07-14T10:45:05+09:00 Subject: Re: Appending to a CSV file I can't speak for the OP, but I am assuming that they were using the CSV module because there might have been some complications in processing the data source. And perhaps some of the CSV module's methods helped streamline things so they didn't have to reinvent the wheel. No matter if you are using the CSV module or rolling your own way of processing a data source file, you would have to parse through the existing data in some block form and then append to the end of the stream/array/whatever to accomplish what the OP was looking to do. If you post a code snippet of your way to accomplishing this without using the CSV module I would think that the basic concept and workflow of the script would be similar... bbiker wrote: > I realize that I am jumping late into this thread. I do not understand > why the responses to "How to append to a csv file" are so complex. Why > do you need a csv module to create, edit, and/or add records to a csv > file. > > As a newbie, I have written Ruby scripts that created csv file and > appended records to existing csv files without having the need for a > csv module. To append a record, I simply open the file in 'a' mode > (have not needed the a+ mode yet), write the record to the file and > then close file. > > I apolized if I am out of term and stuck my nose in the wrong place. > > Chris Hulan wrote: > > James Gray wrote: > > > On Jul 12, 2006, at 1:55 PM, Chris Hulan wrote: > > > > > >> it seems CSV only supports 'r','rb','w','wb' for open. > > >> FasterCSV delegates to an IO object and supports all IO's modes. > > >> So it would be the winner > > > > > > Interestingly, this design choice in FasterCSV has been questioned in > > > the past. I just keep liking it more and more though as issues like > > > this arise. :) > > > > > > James Edward Gray II > > > > It does seem a bit odd that CSV limits the modes. > > > > On the other hand, the desired result can be achieved by creating a > > new file, copy existing data, add the new data, delete (or rename to be > > safe) > > the original and rename the new file to the old file name. > > > > I think supporting the append mode is easier all round... > > > > cheers > > Chris > > > > -- > > Posted via http://www.ruby-forum.com/.