CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: Re: perl script help: Edit Log



perlisgreat
Novice

Jun 22, 2009, 5:26 AM


Views: 17188
Re: perl script help

Hi,

Here is my piece of code.


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-

Code
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

Quote
inside search_for_username_and_no_of_questions
Inside end_block
DETAIL: auth in progress
DETAIL: auth in progress


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

Quote


(This post was edited by namishtiwari on Jun 22, 2009, 8:26 AM)


Edit Log:
Post edited by perlisgreat (Novice) on Jun 22, 2009, 7:12 AM: changed the code a bit, put return 0, when i am getting succes.
Post edited by perlisgreat (Novice) on Jun 22, 2009, 8:23 AM
Post edited by perlisgreat (Novice) on Jun 22, 2009, 8:26 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives