in reply to find and replace
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__
|
|---|