in reply to Global substitution and report

Investigate perl's -i option in perlrun to edit files in place. You'll need to open your log file, too.

Your main loop could look something like:

while ( <$IN> ) { print $LOG $_ if ( s/t/tt/ig ); print $OUT $_; }

A global substitute, as above, isn't going to cause an infinite loop. It'll change

I would like to substitute globally

to

I would like tto substtittutte globally

In-place editing isn't always appropriate, so you may have to write a temp file and rename it once you've processed the input.

Why don't you have a go and come back here if you get stuck?

Good luck!

Replies are listed 'Best First'.
Re^2: Global substitution and report
by Outaspace (Scribe) on Aug 27, 2007 at 08:50 UTC
    But this would disable multi-line substitutions. So I need a way to replace in a text buffer that is loaded from a file.
    I would like to use the same feature also for already loaded files in a editor window.
    I also create a backup of the file before applying the changes so that they can be undone latter.
      In which case, I'd slurp the file in, do the substitutions and write it back out to a temp file. Then I'd run diff on the original & temp files.