I
ironmanda
I have some code that attempts to match a set A of strings against a
set B of strings,
where A ~ 30,000 and B ~ 2,500. A string in A can match any number of
strings in B,
so there is no early exit criteria. The code is roughly:
foreach my $a (keys %A) {
$a=lc($a);
# Repeat the string 3 times so as to allow up to 3!=6 permutations
# of $b to match
$a.=qq( $a $a);
foreach my $b (keys %B) {
# $b is lowercase already
# Allow string fragments of $b to match anywhere in $a - use .*
# in place of spaces
$b=~s/\s+/\.\*/g;
if ($a=~/$b/) {
&doSomething($a, $b);
}
}
}
Is there a faster way to do this?
David
set B of strings,
where A ~ 30,000 and B ~ 2,500. A string in A can match any number of
strings in B,
so there is no early exit criteria. The code is roughly:
foreach my $a (keys %A) {
$a=lc($a);
# Repeat the string 3 times so as to allow up to 3!=6 permutations
# of $b to match
$a.=qq( $a $a);
foreach my $b (keys %B) {
# $b is lowercase already
# Allow string fragments of $b to match anywhere in $a - use .*
# in place of spaces
$b=~s/\s+/\.\*/g;
if ($a=~/$b/) {
&doSomething($a, $b);
}
}
}
Is there a faster way to do this?
David