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

In reply to Re: Algorithm To Select Lines Based On Attributes by perlesque
in thread Algorithm To Select Lines Based On Attributes by ~~David~~

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.