Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^4: trouble parsing log file...

by perl_geoff (Acolyte)
on Nov 20, 2006 at 21:01 UTC ( #585147=note: print w/ replies, xml ) Need Help??


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

Ok, now I understand. Here's what I tried, sorry I wasn't more specific. Unfortunately it only displays green:

$logfile="log.txt"; $error=(/DOWN/); $warn=(/PROBLEM/); $redbutton="\<img src\=\'default_files/perlredblink2\.gif'>"; $greenbutton="\<img src\=\'default_files/perlgreenblink\.gif'>"; $yellowbutton="\<img src\=\'default_files/perlyellowblink\.gif'>"; open LOG, $logfile or die "Cannot open $logfile for read :$!"; # @logarray=<LOG>; # dumps all of $logfile into @logarray use strict; # Set the button to green initially my $button = "perlgreenblink"; # test the file line by line. # The line gets read into $_ # I am testing on the DATA segment to illustrate the point while (<DATA>){ # test with a regex and end the # while loop if there is a problem if (/DOWN/){ $button = "perlredblink2"; last; } if (/PROBLEM/){ $button = "perlyellowblink"; last; } } print "HTML for <img src=\"$button.gif\">\n";


Comment on Re^4: trouble parsing log file...
Download Code
Re^5: trouble parsing log file...
by inman (Curate) on Nov 20, 2006 at 21:18 UTC
    The while (<DATA>){ line needs to read
    while (<LOG>){

    <DATA> file handle is a "special" one that points to the bit in your script following the __DATA__ marker. This is useful to demonstrate the data associated with code in a forum like this.

    As suggested by others, it is good practice to close your file handle once you are finished with it.

    close LOG;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (12)
As of 2014-09-18 17:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (120 votes), past polls