views:

64

answers:

1

Hi, I'm writing a log file parser in Perl, using regexes that I've stored in a database. My workflow is basically like this:

  • Looping over the file and searching for patterns matching my regexes and then extract them
  • Do something with these matches
  • Store them accordingly in a database

Last time I did this I explicitly wrote each regex (not looping through each regex in the database), like this.

Now that I'm doing this again I was wondering if there were better solutions out there, better yet comments on what I've already done.

Thanks! =)

+2  A: 

You might want to check out Regexp::Assemble.

It will let you compose 1 regex that matches all of your regexes. It also claims it can track which of the original patterns the match corresponds too. I have not used this package before, though.

frankc
Looks great, I'll check it out. =)
Lenny Benny
I have used it, it's great. See also: command line tool [`assemble`](http://search.cpan.org/dist/Regexp-Assemble/eg/assemble) (not installed by default) and the improved [`Regexp::Assemble::Compressed`](http://p3rl.org/Regexp::Assemble::Compressed).
daxim
@Lenny Benny I also use Regexp::Assemble in my project Octopussy (which is a log management solution :) ) It's a really good module to speed up your parsing except for some cases like this [one](http://stackoverflow.com/q/1739285/24820).
sebthebert