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
This is handled easily with Perl 5.10
use strict;
use warnings;
use 5.10.1;
my @matches = (
qr'Failed in routing out',
qr'Agent .+ failed',
qr'Record Not Exist in DB'
);
# ...
sub parse{
my($filename) = @_;
open my $file, '<', $filename;
while( my $line = <$file> ){
chomp $line;
# you could use given/when
given( $line ){
when( @matches ){
#...
}
}
# or smartmatch
if( $line ~~ @matches ){
# ...
}
}
}
You could use the new Smart-Match operator ~~.
if( $line ~~ @matches ){ ... }
Or you can use given/when. Which performs the same as using the Smart-Match operator.
given( $line ){
when( @matches ){
#...
}
}