From: ara.t.howard@... Date: 2006-09-28T00:35:55+09:00 Subject: Re: problem with ".scan" On Thu, 28 Sep 2006, Peter Bailey wrote: > unknown wrote: >> On Wed, 27 Sep 2006, Peter Bailey wrote: >> >>> 11 file_contents = File.read(psfile) >>> 12 file_contents.scan(/\%\%Pages: (\d{1,5})[ ]+\n/) do >> >> the modification is probably here. can't you show us everything up >> through >> the matching end? >> >> -a > > Sorry. It's a bit much. That's why I was holding back. Here's the whole > script. > Dir.glob("*.ps").each do |psfile| > file_contents = File.read(psfile) > file_contents.scan(/\%\%Pages: (\d{1,5})[ ]+\n/) do > totalpages = $1 > if (totalpages.to_i % 2) !=0 then > newtotalpages = totalpages.to_i + 1 > file_contents << "\%\%Blank page for Asura.\n\%\%Page: ^^ ^^ ^^ ^^ the modification is question > #{newtotalpages.to_i}\nshowpage\n" > File.open(psfile, "w") { |f| f.print file_contents } > FileUtils.touch(psfile) > end so, ruby is correct, you are modifying a string while in an in-progress scan block. easy-cheasy. kind regards. -a -- in order to be effective truth must penetrate like an arrow - and that is likely to hurt. -- wei wu wei