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

Okay, most important comment first:

What you have there will only ever read one line of your logfile, and then exit. That is because you finish each of your conditional blocks with a last;.

I suspect that you are somewhat confused about what the while ($_ = <LOG>) { line does. From the code you have written, it appears that you are under the impression that it will read the entire file in a single iteration of the while loop. This is not the case. It reads one line at a time. Therefore - because you've included a last in each conditional block - it's going to exit the while loop after reading one line only!

To make the above work like you want it to, you simply need to remove the last from the 2nd and 3rd conditionals. ie. Only use last to exit the loop if you find an "$error". Update: actually, even then it wont work - because you'll be printing your HTML header and a button for EVERY line in your logfile. So you really need to make some changes as I've outlined below.

Now, a couple of other comments:

So, re-writing your code and implementing those few changes:

use strict; use warnings; use CGI qw(standard); my $logfile="log.txt"; my $error="DOWN"; my $warn="PROBLEM"; my $imagedir = 'default_files'; my ($redbutton, $greenbutton, $yellowbutton) = q(perlredblink.gif perlyellowblink.gif perlgreenblink.gif); my $button = $greenbutton; print header(); open LOG, '<', $logfile or die "Cannot open $logfile for read :$!"; while (my $line = <LOG>) { if ($line =~ /$error/i) { $button = $redbutton; last; } elsif ($line =~ /$warn/i) { $button = $yellowbutton; } } close LOG; print qq(<img src="$imagedir/$button">);

Disclaimer: The above is untested, and has been written at 3am after I've just gotten off a flight from Hong Kong to Manila - so it is almost certainly buggy. But I hope it helps anyway ;)

Cheers,
Darren :)