Hi deelinux,
The reason your code isn't working is the way you've saved your regex. In strings surrounded by double quotes, backslash escapes like \d and \s mean something different than in regexes. In fact, \d and \s are not valid in double-quoted strings, only regexes (for details, see Quote Like Operators, perlrebackslash and Gory details of parsing quoted constructs). You can see this if you use Data::Dumper to look at the variable (see also the Basic debugging checklist):
my $match1 = "^$datestring\s+\d{2}:\d{2}:\d{2},\d{3}\s+-\s+\d{2}:\d{2} +:\d{2},\d{3}\s+$SLEVEL1"; use Data::Dumper; $Data::Dumper::Useqq=1; print Dumper($match1); __END__ $VAR1 = "^2017-01-04s+d{2}:d{2}:d{2},d{3}s+-s+d{2}:d{2}:d{2},d{3}s+ERR +OR";
Also, if you had turned on warnings, you would have gotten warnings about this, which is why in my other post I recommended Use strict and warnings!
Personally, I think the best way to fix this is to use qr//. If I do the following, your code starts working:
my $match1 = qr/^$datestring\s+\d{2}:\d{2}:\d{2},\d{3}\s+-\s+\d{2}:\d{ +2}:\d{2},\d{3}\s+$SLEVEL1/;
Hope this helps,
-- Hauke D
In reply to Re: Scan Files - Match String
by haukex
in thread Scan Files - Match String
by deelinux
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |