in reply to regular expression help

Here's a contrived example

#!/usr/bin/perl # Never leave home without these! use strict; use warnings; # Loop through the faux data log, and... while (<DATA>) { # ...find lines that might be interesting... if (/--/) { # ... but ignore certain ones, like those # that say "logging" or "disconnected". unless ( /logging/ || /disconnected/ ) { # Print the rest. print "NOTE: $_"; } } } # Our faux data for this example __DATA__ 081407 start up server 081407 -- fatal error in procedure 1 081407 -- disconnected user 081407 -- logging started 081407 -- not enough space

This produces:

NOTE: 081407 -- fatal error in procedure 1 NOTE: 081407 -- not enough space

Hope this helps,
-v

"Perl. There is no substitute."

Replies are listed 'Best First'.
Re^2: regular expression help
by goibhniu (Hermit) on Aug 15, 2007 at 13:49 UTC

    I like Velaki's approach; take everything and filter out the ones you know you want to ignore. If something new comes in, you can assess that and then update your ignore list if it's not important.

    If you did it the other way (listing only what you want), then something new might be ignored that you actually want.

    In the next value frame, you might externalize the list of known "ignore" patterns. That way you wouldn't be updating your code, but a config file instead.


    I humbly seek wisdom.
Re^2: regular expression help
by wantamad (Initiate) on Aug 14, 2007 at 19:00 UTC
    thank you guys for helping a noob. you have helped a lot! thanks velaki for giving me that code!
      If you want to look up the errors in the logfile for context later on, it would be handy to also print out $. which will contain the line number of the logfile you are currently reading.