in reply to Write to filehandle without deleting current text

Perhaps...
#!/usr/bin/perl -w use strict; my $fileName = "abc"; open(IN, '<', "$fileName") or die "Could not open file $fileName\n"; open(OUT, '>', "$fileName.tmp") or die "Could not open file $fileName.tmp\n"; while (<IN>) { s/foo/bar/g; print OUT $_; } close IN; close OUT; unlink $fileName; rename "$fileName.tmp", $fileName;

Replies are listed 'Best First'.
Re^2: Write to filehandle without deleting current text
by learn_perl_se (Initiate) on Oct 05, 2010 at 09:41 UTC
    Thank You all! Exactly what I was looking for :-)