Perl-Sensitive Sunglasses | |
PerlMonks |
Re: Algorithm To Select Lines Based On Attributesby jethro (Monsignor) |
on Jan 15, 2009 at 18:00 UTC ( [id://736618]=note: print w/replies, xml ) | Need Help?? |
This looks like you might be able to generate some sort of parallel comparision. If you wanted only lines where all rules matched it might even have been possible to use a combination of anding strings together and a regex match, used twice for non-negated and negated. But since you want or, the fastest way I came up is to construct the comparision code into a string and eval that for each line. Sort of compiling the search pattern. For example, if you have two rules that compare attr2 with 'n' and attr4 with '!x', then you could construct the following code string: Now just eval this for each line, having your lines split into @a first. If you need to know which rules matched, construct this instead:
The only thing left is to eval your generated code for each line and check the return value of the eval
In Section
Seekers of Perl Wisdom
|
|