Perl best practices: file parser using regexes and

2019-08-06 10:03发布

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! =)

1条回答
Fickle 薄情
2楼-- · 2019-08-06 10:49

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.

查看更多
登录 后发表回答