2006/5/9, Peter Bailey <pbailey / bna.com>:
> Logan Capaldo wrote:

> > If you are going to File.read the whole file into memory anyway, I
> > would do it once, make _all_ my modifications on the string and then
> > write the whole string out.

> Good idea! Thanks, Logan. I'll try it. I've got a pretty healthy box,
> with lots of memory, so, I may as well just do it all in there at once.
> You're right.

If you cannot do that I guess it's still more efficient to open the
file *once* for reading and writing instead of opening and closing it
all the time and then do all the operations before closing it again.

14:53:21 [tmp]: echo 1 > x
14:53:24 [tmp]: ruby -e 'File.open("x", File::RDWR) {|io| io.seek 0;
puts io.read; io.seek 0, IO::SEEK_END; io.puts "foo"}'
1
14:54:51 [tmp]: cat x
1
foo

HTH

robert
--
Have a look: http://www.flickr.com/photos/fussel-foto/