Perl: the Markov chain saw | |
PerlMonks |
Re: Algorithm To Select Lines Based On Attributesby mr_mischief (Monsignor) |
on Jan 15, 2009 at 17:31 UTC ( [id://736604]=note: print w/replies, xml ) | Need Help?? |
Update: nevermind about my solution. I missed your caveat about what types of rules you have. The advice given at the bottom still stands. Examples are better than prose for many things.
Instead of looking through each line for each defect, look for each defect in every line using an alternating regular expression. This lets you only look through each line once, and gives you the advantage of having the highly optimized regex engine do much of the work.
I'm not even sure where %rulelist or $rulenum are supposed to be set in the above. Do negated defects just not add up, or do they actually remove a defect from the final count? Here I'll assume they just don't get added in. If I'm not misunderstanding your spec, this does everything you need short of reading which defects interest you from another file:
Given this input file for defects: it produces this output:
Now, with a million lines, I'd probably not print the new defects found and the new total for every line. If you need to know which defects had what subtotals, you could accomplish that with a hash:
Given the same input file as above, it produces this output:
A sample of input and a sample of output like this is very helpful in determining whether we're talking about the same spec. If I've made any incorrect assumptions about your spec, please give your own sample input and output so a monk can write a program to match.
In Section
Seekers of Perl Wisdom
|
|