in reply to find and replace
What I noticed: You keep your input file in memory while you read your abreviations line by line.
Depending on the usual size of those files this might be a good choice.
OTOH: I'd expect an inputfile to be substantially larger than your abreviations.
if so you might want to consider to keep the abreviations in memory and to loop over the input lines:
# UNTESTED! use strict; use warnings; open( ABB, '<', 'jabb.txt' ) or die "Couldn't open ABB.\n$!"; open( IN, '<', 'input.txt' ) or die "Couldn't open infile.\n$!"; open( OUT, '>', 'output.out' ) or die "Couldn't open outfile.\n$!"; # prepare abreviations my %abb; while(<ABB>){ # there are shorter ways to do it, but to keep your code... if(/(.*?)\t(.*?)\n/) { $abb{$2}= $1 } } close ABB; # build a RE for quickly(?) finding abbreviatable words. my $abbre= join('|', map "\Q$_\E",keys %abb); $abbre= qr/\b($abbre)\b/; # replace my @myin = <IN>; while(<IN>){ s/$abbre/$abb{$1}/g; print OUT; } close IN; close OUT;
Update: Thanks to Zaxo's obfu-entry ;-) below I noticed I forgot to escape the list of abbreviatable words.
|
|---|