open (INFILE, "< cat.txt" # < = input
open (OUTFILE, "> dog.txt" # > = output
while (<INFILE>) { # loop over the input 'cat.txt' file
print "before: $_";
s/\bcat\b/dog/g; # substitute 'cat' with 'dog' (\b = word boundary)
print OUTFILE; # print this change to the 'dog.txt' outfile
print " after: $_";
}
open (FILE, "<file.txt"
flock (FILE, 2);
undef ($/);
$cont = <FILE>;
close FILE;
$cont =~ s/cat/dog/g; #include boudary if it's the case
open (FILE, ">file.txt"
print FILE $cont;
flock (FILE, 8);
close FILE;
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.