unknown wrote:
> On Thu, 28 Sep 2006, Peter Bailey wrote:
> 
>>> -a
>>
>> Sorry. It's a bit much. That's why I was holding back. Here's the whole
>> script.
> 
> <snip>
> 
>> 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


Thanks. I ended the scan block before doing any file writing. That 
seemed to do the trick. It still confuses me, though, because, this code 
was borrowed from an existing script that I've been using for 6 months, 
and, that part of it is just as you see it above.

-- 
Posted via http://www.ruby-forum.com/.