How can I efficiently match many different regex patterns in Perl?

前端 未结 8 2129
礼貌的吻别
礼貌的吻别 2020-12-18 07:52

I have a growing list of regular expressions that I am using to parse through log files searching for \"interesting\" error and debug statements. I\'m currently breaking th

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-18 08:27

    You might want to get rid of the large if statement:

    my @interesting = (
      qr/Failed in routing out/,
      qr/Agent .+ failed/,
      qr/Record Not Exist in DB/,
    );
    
    return unless $line =~ $_ for @interesting;
    

    although I cannot promise this will improve anything w/o benchmarking with real data.

    It might help if you can anchor your patterns at the beginning so they can fail more quickly.

提交回复
热议问题