David,
One method I've used to speed up something similar in the past is to generate a function containing your rule code in advance of your main processing loop. The advantage of this is all of your rule code is compiled and this should reduce the time taken on each DEFECT iteration. Each DEFECT would then simply be passed to your generated rule function.
A very simple example would be:
my $rule_code = "";
foreach my $rulenum ( keys %$rulelist ){
# one example rule, but there are many..
if ( defined $rulelist->{$rulenum}->{REGION} ){
my $rule = $rulelist->{$rulenum}->{REGION};
if ( $rule =~ s/!// ){
$condition = "!=";
}
else {
$condition = "==";
}
# add the rule to the generated rule code
$rule_code .= 'if ( $line -> {REGIONID} ' . $condition . "$rule
+ ) { return \"$rule\" };\n";
}
}
eval <<EOT;
sub match_rule {
my \$line = shift;
# generated code goes here
$rule_code
return undef; # we did not match any rules!!
};
EOT
Your main loop would then become something like:
DEFECT:
foreach my $defect ( @$list ){
# $summary is my pseudo object,
# this line converts each defect line into a hash
# whose keys are the attributes desired to be selected
my $line = parseLine( $summary, $defect );
if ( ! $line ){ next DEFECT };
# i create a filtered list in the $summary hash
my $rule = match_rule( $line );
if ( defined $rule ) {
push @{$summary->{FILTEREDLIST}->{$rule}}, $defect;
}
}
You may find the generation technique also helpful in making production of your rules simpler/more generic.
Kind Regards
Frank
Perlesque