in reply to In-place editing of files (was: general perl question)
However this code is only the barest code that will work, and should probably not be used without file locks and other sanity checks.my $filename = 'foo.txt'; open IN, "< $filename" or die "Can't open $filename: $!\n"; open OUT, "> $filename.bak" or die "Can't write to $filename: $!\n"; while (<IN>) { s/foo/blah/g; print OUT $_; } close IN; close OUT; rename "$filename.bak", $filename;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: converting files in place
by petdance (Parson) on Apr 24, 2001 at 17:37 UTC | |
by repson (Chaplain) on Apr 25, 2001 at 07:31 UTC |