A
Arturi
Hello there,
I wrote some perl lines that scans a file looking for some words and
substitute them for their corresponding pairs, which are previously
saved in a HASH.
The code is working fine but I'm wondering what could I do to speed it
up.
Does anybody have a hint?
cheers
here the code extract:
----------------------------------------------------------------------
%HASH #is being defined previously
@keys= keys(%HASH);
my $line = undef;
my $tmp = undef;
open(FILE,"< in.txt") || die "Can't open ";
open(OUTPUT2,"< out.txt") || die "Can't open ";
while (<FILE>) {
$line = $_;
foreach $k (@keys) {
if (/(\W)$k(\W)/){
#print "$_\n";
$tmp = $HASH{$k};
while ($line =~/(\W)($k)(\W)/){$line =~
s/(\W)($k)(\W)/$1$tmp$3/;}
}
}
print OUTPUT2 $line;
}
---------------------------------------------------------------------------
I wrote some perl lines that scans a file looking for some words and
substitute them for their corresponding pairs, which are previously
saved in a HASH.
The code is working fine but I'm wondering what could I do to speed it
up.
Does anybody have a hint?
cheers
here the code extract:
----------------------------------------------------------------------
%HASH #is being defined previously
@keys= keys(%HASH);
my $line = undef;
my $tmp = undef;
open(FILE,"< in.txt") || die "Can't open ";
open(OUTPUT2,"< out.txt") || die "Can't open ";
while (<FILE>) {
$line = $_;
foreach $k (@keys) {
if (/(\W)$k(\W)/){
#print "$_\n";
$tmp = $HASH{$k};
while ($line =~/(\W)($k)(\W)/){$line =~
s/(\W)($k)(\W)/$1$tmp$3/;}
}
}
print OUTPUT2 $line;
}
---------------------------------------------------------------------------