I have to replace all the keys in a hash with its respective hash values. This operation is performed in a file.
Below is my code:
my $file= 'IFandENDIF.txt';
my $bak= "$file.bak";
rename $file, $bak or die "cannot rename $file into $bak: $!";
open( my $in, '<', $bak) or die "cannot open $bak: $!";
open( my $out, '>', $file) or die "cannot create $file: $!";
while( <$in>)
{
s/if(exists(%replstr))/$replstr{$1}/xeg;
print {$out} $_;
}
close $in;
close $out;
Please guide me on this.
To replace all instances of keys with hash values:
Note that the
/emodifier treats the replacement as code, not the pattern