Re: [logs] perl question relating to log analysis

From: Sweth Chandramouli (loganalysisat_private)
Date: Wed Sep 04 2002 - 17:04:23 PDT

  • Next message: XiaoMin Zhao: "[logs] Log file relativity analysis"

    	Thanks to Michael Pomraning (<mjpat_private>) for
    catching two big bugs and one piece of laziness in the code I posted:
    
    1) I meant to use an ordered hash, but forgot to.  Add the line
    
    use Tie::IxHash;
    
    	after the "use strict" line, and change the definition
    of the %regexes hash to begin as
    
    my %regexes;
    tie (%regexes, "Tie::IxHash");
    %regexes = (
    
    	, or else all of the sorting will be pointless.
    
    2) That sort is in ascending order, which will un-optimize the matches.
    Change the sort comparison to be:
    
    $regexes{$b}->{"count"} <=> $regexes{$a}->{"count"}
    
    	.
    
    3) I was lazy and &&-ed together all of the actions in the for loop
    rather than using proper flow control, which depending on the action
    for a given regex could cause confusing and buggy behaviour.  A better
    implementation would be:
    
       for my $key (keys %regexes) {
          if ($line =~ $regexes{$key}->{"pattern"}) {
             my $error = $regexes{$key}->{"action"}->();
             if (defined ($regexes{$key}->{"error"}) && $error) {
                $regexes{$key}->{"error"}->($error);
             };
             $regexes{$key}->{"count"}++ && next LINE;
          };
       };
    
    	, assuming that you wanted to trap your error and had defined
    error routines for your actions.
    
    	Sorry to anyone who might have wasted cycles trying to
    get that code to work, and many thanks again to Mike for the catches.
    
    	-- Sweth, who knows better than to post hurried untested
    code but foolishly did so anyway.
    
    -- 
    Sweth Chandramouli      Idiopathic Systems Consulting
    svcat_private      http://www.idiopathic.net/
    _______________________________________________
    LogAnalysis mailing list
    LogAnalysisat_private
    http://lists.shmoo.com/mailman/listinfo/loganalysis
    



    This archive was generated by hypermail 2b30 : Wed Sep 04 2002 - 21:01:26 PDT