From: Peter Bailey Date: 2006-11-08T03:41:57+09:00 Subject: Re: Why am I getting this string error? ... 20 Dir.glob("*.ps").each do |psfile| 21 $filetime = File.ctime(psfile) 22 $filetime = $filetime.to_s.gsub!(/ -.*$/, "") 23 file_contents = File.read(psfile) 24 file_contents.scan(/\%\%Pages: (\d{1,5})[ ]+\n/) do 25 totalpages = $1 26 if (totalpages.to_i % 2) !=0 then 27 totalpages = totalpages.to_i + 1 28 file_contents. << "\%\%Blank page for Asura.\n\%\%Page: 29 #{totalpages.to_i}\nshowpage\n" 30 File.open(psfile, "w") { |f| f.print file_contents } 31 FileUtils.touch(psfile) 32 end ... You're modifying file_contents during scan, so scan gets confused. from what I see, you'd better use gsub! with a block, since, if I understood your point, you are basically inserting text where you detect something. Vince Thanks, Vince. I see what you mean, and, I did change it to use a gsub!. I've always thought of gsub as a changer for little things, not huge files like this, but, it works fine. Thanks again. -- Posted via http://www.ruby-forum.com/.