error in output of perl script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting error in output of perl script
# 1  
Old 06-12-2009
error in output of perl script

Hi,

This is my piece of code.
Code:
my $logFile = $ARGV[0]; 
die "usage: $0 <logFile>" unless $logFile; 
die "Logfile $logFile doesn't exist" unless -f "$logFile"; 
open(my $log, "<", $logFile) or die "Can't open $logFile for reading."; 
print "Processing file $logFile...\n"; 
#my $authenticates = {}; 
my $n = 0;
my $ArcotIDError_Count = 0;
my $QnAError_Count = 0;
my $UPError_Count = 0;
my $OTPError_Count = 0;
my $errorCode;
while(my $line = <$log>) { 
   	$n++; 
    $line =~ tr/\r\n//d; 
	if($line =~ /Handling NSPAdvice for mechanism \[4\]/) {
		while ( $line = <$log> ) {
			if ($line =~ /Authentication mechanism returned \[(\d+)\]/) {
				my $errorCode = $1;
				print "$errorCode\n";
				if ($errorCode != 0 && $errorCode != 1) {
                  $ArcotIDError_Count++;
				}
			}
			next;
		}
	}	
	}
	print "Total Number Of ArcotID Authentication ErrorCode returned is $ArcotIDError_Count\n";

The output for this comes as 354 but the actual output is 142. I am not finding any problem in the code and logic also seems to me ok.
Can anyone suggest me if any problem is there.
One more thing i like to know is that--
I can add OR condition in this statement
Code:
if($line =~ /Handling NSPAdvice for mechanism \[4\]/)
as
if($line =~ /Handling NSPAdvice for mechanism \[4\]/ || /Handling NSPAdvice for mechanism \[3\]/)

any other better way to do it here.

Thanks
NT
# 2  
Old 06-15-2009
Please advise me for the likely reasons, is there any problem in the code.

Thanks
NT
# 3  
Old 06-15-2009
Hi NT,

Don't know if I personally can be of any help, but I if you supply the contents of the $logFile, perhaps this will be useful for the persons trying to help.

You can also try to use the debugger (#!/bin/perl -w -d) to see where the code does something different than expected.

And do you expect 354 as output but you get 142, or do you get 142 where you expect 354 ?

E.J.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl script to find process and exclude strings from the output

Hi team, I'm a newbie of Perl Script and looking to create a simple perl script that will run in the Linux system: 1) to find process, such as ps -ef | grep process name 2) to exclude strings from the output if it found, for instance if i see abc from usr process, then will exclude it from... (1 Reply)
Discussion started by: hoffman2503
1 Replies

2. Shell Programming and Scripting

Perl Script output

Hi All, I have an expect script that I would like a perl script to call in order to login to a node and run in a single command. The command being running is a log of events so has lots of data that will be output. I would like to output that data to a file. Would anyone be kind enought... (1 Reply)
Discussion started by: mutley2202
1 Replies

3. Shell Programming and Scripting

Storing the Linux command output to an array in perl script

Hi I am trying to store the output of a command into an array in perl script. I am able to store but the problem is i am unable to print the array line with one line space. i mean i inserted the \n in loop ...but not getting the result. I have written like this #!/usr/bin/perl @a =... (2 Replies)
Discussion started by: kumar85shiv
2 Replies

4. Shell Programming and Scripting

Help with perl script to output data in table format...

Hello, I need help with a perl script that will process a text file and match virtual server name to profile(s). the rest will be ignored. Virtual server name follows the word "virtual" in the begging of the line. There could be multiple profiles assigned to one virtual server. For example, ... (3 Replies)
Discussion started by: besogon
3 Replies

5. Shell Programming and Scripting

Output after a perl script gives a file with size zero.

Hi, I have a unix shell script which generates a flat file after connecting to Teradata servers to fetch tables and views and also picks up modified unix scripts from the specified paths. Later on the script calls a perl script to assign a value based on the type of object in the flat file which... (2 Replies)
Discussion started by: yohasini
2 Replies

6. Shell Programming and Scripting

Perl CGI. no output until backend script is done

It is a basic Perl CGI question, I want to print out "Processing ... " while backend script /script/wait.pl is still running. But acctually, nothing appeared in browser untill /script/wait.pl finished. print "Content-type:text/html\r\n\r\n"; print '<html>'; print '<head>'; print... (4 Replies)
Discussion started by: honglus
4 Replies

7. Shell Programming and Scripting

Using output of perl script in shell

Hi, I have a perl script which prints the epoch value of given date. I want to use its output in a shell script.Can someone suggest me how to do it. Thanks and Regards Jyothi (4 Replies)
Discussion started by: jyothi_wipro
4 Replies

8. Shell Programming and Scripting

Help need to write a script on column separation for syslog output in perl

HI Pros, I have a issue.I need to write a script to parse the logs got from syslog server and update the same in my database.I need the following output.I donot know perl and I heard it very easy to write in perl I have the sample log I need each column seperated by commas and all equals... (0 Replies)
Discussion started by: iron_michael86
0 Replies

9. Shell Programming and Scripting

how to get split output of a file, using perl script

Hi, I have file: data.log.1 ### s1 main.build.3495 main.build.199 main.build.3408 ###s2 main.build.3495 main.build.3408 main.build.199 I want to read this file and store in two arrays in Perl. I have following command, which is working fine on command prompt. perl -n -e... (1 Reply)
Discussion started by: ashvini
1 Replies

10. Shell Programming and Scripting

wrong output in perl script

Hi, Here is my piece of code-- #!/usr/bin/perl my $Time_Stamp ; my $User_Name; my $Success; my $Failure; my $ErrorCode; my $ErrorMsg; my $logDir = $ARGV; my $logPrefix = $ARGV; die "usage: $0 <logDir> <logPrefix>" unless $logDir and $logPrefix; die "Log dir $logDir doesn't... (2 Replies)
Discussion started by: namishtiwari
2 Replies
Login or Register to Ask a Question