Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^4: trouble parsing log file...

by SheridanCat (Pilgrim)
on Nov 20, 2006 at 22:05 UTC ( #585155=note: print w/replies, xml ) Need Help??

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

Okay, let's see what we can do here.

First off, your assignments to $error and $warn probably aren't doing what you think they're doing. If you "use warnings" and "use strict" at the top of your code, you'll see an error that is telling:

Use of uninitialized value in pattern match (m//)

Just set $error = 'down' and $warn = 'problem'. Worry about the regular expression stuff later in the code.

As someone already mentioned, why not go ahead and set the $got_button variable to $greenbutton before you enter the loop? It's nice to have a default state already setup. Then there's no need to do any gymnastics at the end to set it.

Inside the loop, you have the right idea. Try using a regular expression there. So the "if" clause would look something like:

if( $line =~ m/$error/i ){

I used the "i" modifier to make it case insensitive, just in case someone changes log messages on you some day.

As someone already pointed out, reading the whole log into memory may not be a very good idea since you're bailing out as soon as you find a red/yellow state, so consider just processing the file a line at a time using <LOG>.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://585155]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2017-06-25 09:42 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (565 votes). Check out past polls.