Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^4: trouble parsing log file...

by liverpole (Monsignor)
on Nov 20, 2006 at 22:06 UTC ( #585156=note: print w/ replies, xml ) Need Help??


in reply to Re^3: trouble parsing log file...
in thread trouble parsing log file...

You need to look at my example more closely.

With regular expressions, you can't just set a string to $error=(/DOWN/), and then check whether your line matches it with if ($line eq $error) {.

You need to use the regular expression match operator =~ to see whether your string matches the pattern:

if ($line =~ /DOWN/) { # ... } elsif ($line =~ /PROBLEM/) { # ... }

Now, it's true that you can abstract some of this.  For example, you could assign string variables, and then use pattern matching on those variables:

my $error = "DOWN"; my $warn = "PROBLEM"; # ... and later ... if ($line =~ /$error/) { # ... } elsif ($line =~ /$warn/) { # ... }

Which in the above case should work fine.

But be aware that, if your variable contains any characters which have special meaning within regular expressions, those meanings will continue to apply.

For example, if the string you're trying to match is literally "Server ... DOWN", and you attempt to assign and match against that string with:

my $error = "Server ... DOWN"; if ($line =~ /$error/) { # conditional clause }

then you'll be using the special meaning of "." within a regular expression (that of matching any character other than end-of-line), and your conditional will thus also match strings like the hypothetical "Server Not DOWN".


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/


Comment on Re^4: trouble parsing log file...
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://585156]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2014-11-24 00:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (134 votes), past polls