Hi,
I am trying to find and replace a particular string in a file and save that file.
Here is what I did, where I am writing the output after replacement into new file.
I was trying to avoid to open the file for writing and try to use just s/// to do replacement in the same file. But its not working.
Any help would be appreciated.
Thanks
#!/usr/bin/perl
use strict;
use warnings;
open INPUT, "abc.txt" or die "Cannot open ldif file for reading : $!";
open OUTPUT, ">Newabc.txt" or die "Cannot open ldif file for writing : $!";
my $pattern = "old";
my $new = "new";
my @file = <INPUT>;
foreach (@file) {
$_ =~ s/\b$pattern\b/$new/g;
print OUTPUT $_;
}