Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^3: trouble parsing log file...

by inman (Curate)
on Nov 20, 2006 at 20:02 UTC ( #585128=note: print w/ replies, xml ) Need Help??

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

Dumping a multi Gigabyte log file into an array is going to get ugly quickly. A combination of the Perl internals and the IO buffering on the computer should take care of this situation line by line.

Comment on Re^3: trouble parsing log file...
Replies are listed 'Best First'.
Re^4: trouble parsing log file...
by perl_geoff (Acolyte) on Nov 22, 2006 at 14:12 UTC
    Here's what I have:
    use strict; use warnings; my $logfile="log.txt"; my $error="DOWN"; my $warn="PROBLEM"; my $redbutton="\<img src\=\'default_files/perlredblink\.gif'>"; my $greenbutton="\<img src\=\'default_files/perlgreenblink\.gif'>"; my $yellowbutton="\<img src\=\'default_files/perlyellowblink\.gif'>"; open LOG, $logfile or die "Cannot open $logfile for read :$!"; my $button = $greenbutton; while ($_ = <LOG>) { if ($_ =~ /$error/i) { $button = $redbutton; print "<!--Content-type: text/html-->\n\n"; print "$button"; last; } elsif ($_ =~ /$warn/i) { $button = $yellowbutton; print "<!--Content-type: text/html-->\n\n"; print "$button"; last; } else { print "<!--Content-type: text/html-->\n\n"; print "$button"; last; } } close LOG;
    Unfortunately, it does everything I want except go through the log line by line. How can I safely get this program to do that? Can you explain the alternative to using an array and/or a safe way to do this using an array? Thanks!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2015-12-02 01:27 GMT
Find Nodes?
    Voting Booth?

    My keyboard shows this many letters:

    Results (31 votes), past polls