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

Re: problem in output

by Util (Priest)
on Jun 29, 2009 at 15:47 UTC ( [id://775716]=note: print w/replies, xml ) Need Help??


in reply to problem in output

Hidden Bug:

if ($line =~ /Entering UPAuthModule::authenticate/ .. /Sending Invalid + credential/ )
omits the `$line =~` from the second half of the flip-flip operands. It should read:
if ( ( $line =~ /Entering UPAuthModule::authenticate/ ) .. ( $line =~ +/Sending Invalid credential/ ) )

Subtle Bug: It is usually wrong to use printf() with variables imbedded in the template. From `perldoc -f printf`:

Don't fall into the trap of using a "printf" when a simple "print" would do. The "print" is more efficient and less error prone.
Either use print "Total is $total\n"; or printf "Total is %d\n", $total;.

Other than that, I think davorg++ has pointed out the major problem; you are only actually processing the last log file. Here is an example of refactored flow:

#!/usr/bin/perl use strict; use warnings; my $usage = "usage: $0 <logDir> <logPrefix>"; die "$usage\n" if @ARGV != 2; my ( $dir, $prefix ) = @ARGV; die "Log dir '$dir' doesn't exist" unless -d $dir; my $glob_path = "$dir/${prefix}*"; my @log_paths = glob $glob_path or die "No files found in '$glob_path'"; Total_Number_Of_Transactions( @log_paths ); sub Total_Number_Of_Transactions { die if not @_; my @log_files = @_; my $Success_QnA_Count, $Success_ArcotID_Count, $Success_OTP_Count, + $Success_UP_Count ) = ( 0, 0, 0, 0 ); my $Failure_QnA_Count, $Failure_ArcotID_Count, $Failure_OTP_Count, + $Failure_UP_Count ) = ( 0, 0, 0, 0 ); my $total_filename = 'total_transactions'; for my $log_file (@log_files) { open my $log, '<', $log_file or die "Can't open '$log_file' for reading."; while( <$log> ) { s{\s+\z}{}; do { $Success_ArcotID_Count++; next } if /ArcotID\s*Auth\s +*SUCCESS/; do { $Failure_ArcotID_Count++; next } if /Auth failed/; do { $Success_QnA_Count++ ; next } if /QNA Auth - Succe +ss/; do { $Failure_QnA_Count++ ; next } if /Message: QNA Aut +h Failed/; do { $Success_OTP_Count++ ; next } if /OTP SUCCESS/; do { $Failure_OTP_Count++ ; next } if /Message: OTP FAI +LED/; do { $Success_UP_Count++ ; next } if /UPAuth SUCCESS/; do { $Failure_UP_Count++ ; next } if /UPAuth FAILED/; } close $log or warn; } open my $total_fh, '>', $total_filename or die "Cannot create file '$total_filename' for writing"; printf $total_fh "%7d Total count for ApricotID\n" , $Success +_ArcotID_Count + $Failure_ArcotID_Count; printf $total_fh "%7d Total count for QnA\n" , $Success +_QnA_Count + $Failure_QnA_Count; printf $total_fh "%7d Total count for OTP\n" , $Success +_OTP_Count + $Failure_OTP_Count; printf $total_fh "%7d Total count for User Password \n", $Success +_UP_Count + $Failure_UP_Count; close $total_fh or warn; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-25 19:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found