Your main loop would then become something like: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
You may find the generation technique also helpful in making production of your rules simpler/more generic. Kind Regards Frank PerlesqueDEFECT: 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; } }
In reply to Re: Algorithm To Select Lines Based On Attributes
by perlesque
in thread Algorithm To Select Lines Based On Attributes
by ~~David~~
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |