Logan Capaldo wrote: > On May 9, 2006, at 2:58 PM, Peter Bailey wrote: > >>>> end >>> file is closed before returning. >>> >> >> blankpages = [] >> page >> blankpages = $1 >> >> -- >> Posted via http://www.ruby-forum.com/. >> > > 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. > > e.g. > > file_contents = File.read(psfile) > > file_contents.scan(\%\%Pages: (\d{1,5})\n/) do > if odd > file_contents << blank_page > end > end > > file_contents.scan(/\%\%Page: [(\d)()]+ > (\d{1,5})\n\%\%PageBoundingBox: > \d{1,5} \d{1,5} \d{1,5} \d{1,5}\n\%\%PageOrientation:/) do > ... > end > > File.open(psfile, "w") { |f| f.print file_contents } 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. -Peter -- Posted via http://www.ruby-forum.com/.