From: Li Chen Date: 2008-09-21T07:47:27+09:00 Subject: Re: update a field in CSV file using fastercsv Gregory Brown wrote: > On Sat, Sep 20, 2008 at 5:19 PM, Li Chen wrote: >>> 1. Open the existing data for reading >> Thank you very much. >> >> One more question: Is this the same idea behind what we do with 'save' >> or 'save as' in microsofte WORD or EXCEL? > > An atomic save, as James suggested by the 4 steps above, is > essentially the same as a "Save" in Word or Excel. > > A Save is just two "Save As" calls. > > I've got a file called "A" > I make some changes to it, then > I save it as "B" > Once I am sure that my changes to "B" are okay, I save it as "A", to > replace the original file. > > The reason we need to do things this way is that (at least in Ruby, > but in most languages I'd imagine), there isn't really a way to make a > change to a file while you're reading it. > > So we read in the file, writing another file with our changes. > Then when we're done reading and writing, we replace the old file with > our new one. Conceptually, this ends up accomplishing the same thing, > it lets us make changes to a single file. The second file is just a > temporary file for doing work on. > > Make sense? > > -greg They really make sense. Thank you very much, Li -- Posted via http://www.ruby-forum.com/.