|Problems? Is your data what you think it is?|
Re^4: trouble parsing log file...by SheridanCat (Pilgrim)
|on Nov 20, 2006 at 22:05 UTC||Need Help??|
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:
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>.