in reply to problem in output

As we don't know what the input looks like, we can only guess. One problem I see: Your code assumes that between a transaction (between 'Entering xxx' and 'xxx SUCCESS' or 'XXX FAILED') no other transaction can insert lines into the logfile or it would not be counted. In most cases I know this is not true. In other words: if you step over an interleaved 'Entering yyy' while looking for a 'XXX' success or failure it doesn't get counted

To solve this you could just count SUCCESS and FAILURE lines. You don't seem to do anything with the 'Entering' lines, so why bother?

If that is not a good idea (because of integrity or security concerns) you would have to use a hash or something to remember which 'Entering' lines you already encountered

BTW in lines like if ($line =~ /OTP SUCCESS.*/) the .* is useless and can be dropped without changing anything. Regexes look for string parts if you don't anker them with ^ or $

Replies are listed 'Best First'.
Re^2: problem in output
by Marshall (Canon) on Jun 29, 2009 at 16:44 UTC
    Yes! This appears to be a simple peg count of particular lines. I don't see the need for anything complex. Maybe the Op can tell us if this works? Of course some tweaking of the regex'es...but looks like straight line code to me. I echo previous comments about "use strict; use warnings;".
    while( my $line = <$log> ) { $Success_ArcotID_Count++ if ($line =~ /ArcotID\s*Auth\s*SUCCESS.*/); $Failure_ArcotID_Count++ if ($line =~ /Auth failed.*/); $Success_QnA_Count++ if ($line =~ /QNA Auth - Success.*/); $Failure_QnA_Count++ if ($line =~ /Message: QNA Auth Failed.*/); $Success_OTP_Count++ if ($line =~ /OTP SUCCESS.*/); $Failure_OTP_Count++ if ($line =~ /Message: OTP FAILED.*/); $Success_UP_Count++ if ($line =~ /UPAuth SUCCESS.*/); $Failure_UP_Count++ if ($line =~ /UPAuth FAILED.*/); }
    If the above does indeed "work" in this application, it can be re-written so that token before either "SUCCESS" or "FAILED" creates a hash table peg count without needing this big "=0" declaration at the front.

    I think others have covered the open ">$file" "clobbers previous $file" problem. If you want append, use ">>" for the open. Glob isn't portable, but that's a different subject. Get the basic stuff working and then we'll talk about that detail.