open(IN, "textfile" or die "cannot open textfile\n";
open(OUT,">temporarytextfile" or die "cannot open temporarytextfile"
my $searchstring="Some string";
while(<IN>){
my $line=$_;
$line=~s/$searchstring//; #replace it with null string
print OUT "$line";}
#now delete textfile
unlink "textfile";
#and replace it by temporarytextfile this can be done
# via a system call, so let's first determine OS
my $Operating_system=$^O;
$Operating_system=uc($Operating_system);
unless($Operating_system=~/MSWIN32/){
system ("mv temporarytextfile textfile"#use the Unix move function
}else{#a Windows machine..
system ("copy temporarytextfile textfile"#
system ("delete temporarytextfile"
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.