You can translate jabb.txt into a hash and substitute directly like this: (untested)
The less tricky part there is reversing the map over split so the full text is the key in %jabb. The really tricky part is combining and escaping the keys of %jabb with '|' to get a big alternation on the keys of %jabb so we can substitute the hash value for the key we find. If the values to substitute for have overlap at the initial position, you should order them so that the longest match is tried firstmy %jabb = do { open my $fh, '<', '/path/to/jabb.txt' or die $!; map { reverse split; } <$fh>; }; my $re = do { local $" = '|'; qr!\b(@{[map { qr/\Q$_\E/ keys %jabb]})\b!; }; open my $in, '<', '/another/path/to/input.txt' or die $!; open my $out, '>', '/the/path/to/output.txt' or die $!; while (<$in>) { s/$re/$jabb{$1}/g; print $out $_; }
After Compline,
Zaxo
In reply to Re: find and replace
by Zaxo
in thread find and replace
by texuser74
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |