Either you want inplace edit with the $^I variable; or write the results to a temporary file created with File::Temp::tempfile and then rename the new file to the original one.
Here's an example for the second one:
use warnings; use strict; use File::Temp "tempfile"; my $i = "yourfile.txt"; # filename my ($O, $o) = tempfile; open my $I, $i or die "open: $!"; while (<$I>) { s/foo/bar/g; print $O $_; } close $O or die; rename $o, $i; __END__
In reply to Re: find and replace
by ambrus
in thread find and replace
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |