in reply to Global substitution and report

If you use the /g modifier, you won't have infinite loops.

while (my $line = <$infile>){ if ($line =~ s/T/TT/g){ # log $line and $. (line number) } print $new_file $line; } # overwrite old file with new file here

Replies are listed 'Best First'.
Re^2: Global substitution and report
by Outaspace (Scribe) on Aug 27, 2007 at 08:57 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.