|We don't bite newbies here... much|
Matching against list of patternsby Eyck (Priest)
|on Sep 16, 2004 at 11:50 UTC||Need Help??|
Eyck has asked for the
wisdom of the Perl Monks concerning the following question:
Hi, I find myself writting another app this month that requires matching against list of patterns, what I did the last time is:
This is straitghtforwad and it works.
The problem is that it grows roughly N**2, (because there is relation between number of lines to parse, and amount of possible patterns).
UPDATE: I keep patterns in hashref because the whole point of this excercise is to figure out WHICH regexp matched. ORing patterns together might be fine if I knew how to figure out which patter from such ORed pattern matched exactly.
What do people do with such problems? Is it possible to optimise this? ( for example, group patterns into eee...groups based on common prefix or something common, or maybe preprocess those lines, split sentences into functional parts .. )
This seems like rather common task, are there any smart (or at least working) solutions?