Hidden Bug:
omits the `$line =~` from the second half of the flip-flip operands. It should read:if ($line =~ /Entering UPAuthModule::authenticate/ .. /Sending Invalid + credential/ )
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; }
In reply to Re: problem in output
by Util
in thread problem in output
by namishtiwari
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |