in reply to Re: file input output problem
in thread file input output problem

so bascially, my only option is
./perl.file done.txt > done.temp
and then
cat done.temp > done.txt

Replies are listed 'Best First'.
Re^3: file input output problem
by Argel (Prior) on Aug 07, 2007 at 23:50 UTC
    If the file is relatively small you could just read all of it into memory and then overwrite the file after you have made your changes.
    #!/usr/bin/perl use strict; use warnings; my @contents; my $file = 'done.txt'; open IN, '<', $file or die "Could not open $file for reading."; while (<IN>) { $_ =~ s/yahoo/never/g; push @contents, $_; } close IN or die "Could not close $file after reading."; open OUT, '>', $file or die "Could not open $file for writing."; foreach my $line ( @contents ) { print OUT $line or die "Failed to write to $file ($line)." } close OUT or die "Could not close $file after writing.";