<?xml version="1.0" encoding="windows-1252"?>
<node id="585115" title="trouble parsing log file..." created="2006-11-20 14:27:34" updated="2006-11-20 09:27:34">
<type id="115">
perlquestion</type>
<author id="585113">
perl_geoff</author>
<data>
<field name="doctext">
Hi, I am writing a perl script which will parse a log file on my server and display either a red, yellow or green light depending on if it catches an error or warning string in a webpage. If it doesn't see any of those strings, it will display a green light. I'm having trouble with my if and elsif statements that handle this.  Right now my script parses my log file, but it only displays the green light, even though my sample logfile says "server DOWN." Also, I'm not sure if I should put these statements inside a loop; I think I may have to eventually, because my real log files will have several lines and will have to be parsed for all different types of warnings and errors. I tried a while loop with this, and got an infinite loop.
Here's what I have so far:
&lt;code&gt;
$logfile="log.txt";
$error="DOWN";
$warn="PROBLEM";
$redbutton="\&lt;img src\=\'default_files/perlredblink2\.gif'&gt;";
$greenbutton="\&lt;img src\=\'default_files/perlgreenblink\.gif'&gt;";
$yellowbutton="\&lt;img src\=\'default_files/perlyellowblink\.gif'&gt;";

open LOG, $logfile or die "Cannot open $logfile for read :$!";

@logarray=&lt;LOG&gt;;   # dumps all of $logfile into @logarray

if (@logarray eq $error) {
  print "&lt;!--Content-type: text/html--&gt;\n";
     print "$redbutton";
}
elsif (@logarray eq $warn) {
print "&lt;!--Content-type: text/html--&gt;\n";
     print "$yellowbutton";
}
else {
print "&lt;!--Content-type: text/html--&gt;\n";
     print "$greenbutton";
}
&lt;/code&gt;
Thanks for any help!</field>
</data>
</node>
