in reply to simple substitution

Try this:

my $file = "file.txt"; open IN, "<$file" or die; open OUT, ">$file.tmp" or die; while ( my $line = <IN> ) { $line =~ s/word1/word2/g; print OUT $line; } close IN; close OUT or die; rename "$file.tmp", $file;

But be careful in a multi-user or multi-process environment, especially such as CGI programming though, because no file locking is done, and the tempfile's name might already be in use by another instance of the process. If you turn this into CGI be sure to lock your files. And don't obtain "$file" from the user.


Dave

Replies are listed 'Best First'.
Re: Re: simple substitution
by wolverina (Beadle) on Jan 05, 2004 at 08:04 UTC
    that did the trick... thanx... wolfy.