problem in perl script

Hi,

Here is my piece of code.

#!/usr/bin/perl

my $logFile = $ARGV[0];

die "usage: $0 <logFile>" unless $logFile;
die "Logfile $logFile doesn't exist" unless -f "$logFile";

my %no_of_questions;
my %timestamp;
open (FP,"<$logFile") or die "unable to open file $!" ;
@records=<FP>;
chomp(@records);

for($index=0;$index<@records;$index++)
	{
		if($records[$index] =~ /^(.*)INFO:.*Entering QnAModule::authenticate/)
		{
			#printf "in INFO:.*Entering QnAModule::authenticate\n";
			$Time_Stamp = $1;
			#die "Some error in search_for_username_and_no_of_questions" if (search_for_username_and_no_of_questions() == -1);
			#die "Some error in end_block" if (end_block() == -1);
			search_for_username_and_no_of_questions();
			end_block();

		}
		#last;
	}		
			
			


sub search_for_username_and_no_of_questions
{
printf "inside search_for_username_and_no_of_questions\n";
			for($index=0;$index<@records;$index++)
			{
				if ($records[$index] =~ /userName :\[(..*)\]/) 
				{
					#printf "in user name identification \n";
					$User_Name = $1;
					$User_Name =~ s/\s+//g;
					for(;$index<@records;$index++)
					{
						if ($records[$index] =~ /Set of questions\(bitmap\) selected : (\d+)/) 
						{
							#printf "in set of questions\n";
							$Bitmap_Number_For_Questions = $1;
							$no_of_questions{$User_Name}=$Bitmap_Number_For_Questions;
							$timestamp{$User_Name}=$Time_Stamp;
							#printf "DETAIL: LINE NO: $index\n";
							#printf "$Time_Stamp,$User_Name,$Bitmap_Number_For_Questions\n";
							return 0;
						}
					}
				
					
			}
		last;
    }
}

sub end_block
{
printf "Inside end_block\n";
	for($index=0;$index<@records;$index++)
	{
		
		if($records[$index] =~ /QNA Step.*AUTH IN PROGRESS/)
		{
			printf "DETAIL: auth in progress\n";
			for(;$index<@records;$index++)
			{
				if ($records[$index] =~ /ArAuthFrameworkImpl::doPostAuth.*Authentication mechanism returned \[(..*)\] for AuthIdentity \[(..*)\]/)
				{
					#printf "done one request \n";
					#printf "$records[$index]\n";
					my $return_code = $1;
					my $temp_user = $2;
					$temp_user =~ s/\s+//g;
					#printf "user = $temp_user\n";
					if(exists($no_of_questions{$temp_user}))
					{
						if ($return_code == 0) 
						{
							printf "$temp_user,$no_of_questions{$temp_user} , $timestamp{$temp_user} , \"Success\" \n";
							return 0;
						}
						elsif ($return_code > 1)
						{
							printf "$temp_user,$no_of_questions{$temp_user} , $timestamp{$temp_user} , \"Failure\" \n";
							return 0;
						}
						for(;$index<@records;$index++)
						{
							if ( ($records[$index] =~ /Prepared to Send OK/) || ($records[$index] =~ /Sending Invalid credential/) )
							{
								#printf "end of file\n";
							}
						}
					}				
				}
				last;
			}
		}
	}
	#return -1;
}




here is the sample data-

monday 12:55:66 INFO:Entering QnAModule::authenticate
monday 12:55:66 userName :[prasanna]
monday 12:55:66 Set of questions(bitmap) selected : 13
monday 12:55:66 QNA Step.*AUTH IN PROGRESS
monday 12:55:66 ArAuthFrameworkImpl::doPostAuth.*Authentication mechanism returned [4] for AuthIdentity [prasanna]
monday 12:55:66 Prepared to Send OK 
monday 12:55:66 Sending Invalid credential
monday 12:55:66 INFO:Entering QnAModule::authenticate
monday 12:55:66 userName :[prasanna]
monday 12:55:66 Set of questions(bitmap) selected : 13
monday 12:55:66 QNA Step.*AUTH IN PROGRESS
monday 12:55:66 ArAuthFrameworkImpl::doPostAuth.*Authentication mechanism returned [4] for AuthIdentity [prasanna]
monday 12:55:66 Prepared to Send OK 
monday 12:55:66 Sending Invalid credential

when i ran the script on this data i got the actual result ie

it did not print any data. Kindly give some suggestions.
Thanks
NT

[quote]

What is the output you were expecting?

A good first step is to add "use strict;" and "use warnings;".

You may want to invoke your script with the "-d" option which will start the debugger, and just step through the code. That way you will know where exactly you should've printed the data from the file.

tyler_durden

when i used

use strict;
use warnings;

in my code i got so many warning message like this --

Global symbol "$index" requires explicit package name at per_user_qna_detail.pl
line 67.

This error came for all the global symbol.
How i can get rid of this.

The expeted output is the print statement in my script.

Thanks
NT

The variable in question wasn't 'declared' with 'my'.

It seems likely that one of those conditionals never turns out to be true. One way to track this down is with the debugger, as mentioned above.

Another method is to print statement at the beginning of each block along the lines "I am now in if block 2". When you see which block you don't end up in, you can then add a new print statement just above, printing out the values that the conditional depends on, and from there work out why they are not what you expect. From the commented out print statements, it looks like you started doing something along those lines already.

A minor nitpick ... it doesn't look like you use any formatting lines with all of those printf()'s, you could use plain old 'print' instead.