in reply to reading/writing line by line
open (INFILE, "input.txt"); open (OUTFILE, ">output.txt"); while (INFILE) { $_ =~ s/foo/bar/gms; print OUTFILE "$_\n"; }
/m is multi line: not useful when dealing with a single line at a time. /s makes . match newline: not useful if you don't use ..
One liner:
perl -i.backup -pe's/foo/bar/g' filename
Same thing, inside a larger script that you don't want to have using -i all the time:
{ local @ARGV = ('filename'); local $^I = '.backup'; local $_; while (<>) { s/y/yah/g; print; } }
- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: reading/writing line by line
by amarceluk (Beadle) on May 22, 2002 at 18:22 UTC | |
by amarceluk (Beadle) on May 22, 2002 at 19:42 UTC | |
by Juerd (Abbot) on May 22, 2002 at 19:44 UTC | |
by amarceluk (Beadle) on May 22, 2002 at 19:51 UTC |