I do not see what your code requires absolutely regexp 2, but if you do not want my solution only uses one, it's the same. Here's the problem
Code:
($ip,$day,$month,$year,$method,$page,$ret_code,$byte,$referer,$user_a) = $line =~ $EXPREG;($ip,$day,$month,$year,$method,$page,$ret_code,$byte,$referer,$user_a) = $line =~ $EXPREG1;
make use of "if"
Code:
if ($line =~ $EXPREG){
($ip,$day,$month,$year,$method,$page,$ret_code,$byte,$referer,$user_a) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);
}
elsif ($line =~ $EXPREG1){
($ip,$day,$month,$year,$method,$page,$ret_code,$byte,$referer,$user_a) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);
}
For
Code:
my $EXPREG = q{(\S+)\s+\S*\s+\S*\s+\[(\d+)\/(\D+)\/(\d+):\d+:\d+:\d+\s+\+\d+\] \"(.*) (.*)\" (\S+) (\S+) \"(.*)\" \"(.*)\"};
use
Code:
my $EXPREG = q{(\S+)\s+\S*\s+\S*\s+\[(\d+)/(\D+)/(\d+):\d+:\d+:\d+\s+\+\d+\] "(.*) (.*)" (\S+) (\S+) "(.*)" "(.*)"};
The double quotes should not be escaped by a backslash. To escape the slash by a backslash is necessary if you use m// (it is also advisable to use m () instead)
Bookmarks