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:
perl script help

 

First page Previous page 1 2 Next page Last page  View All


KevinR
Veteran


Jun 23, 2009, 8:34 AM

Post #26 of 36 (7160 views)
Re: [namishtiwari] perl script help [In reply to] Can't Post

change lines like this:


Code
for($index=0;$index<@records;$index++)


change to:


Code
for(my $index=0;$index<@records;$index++)


see if that clears up all or nearly all the errors about packaging "$index"
-------------------------------------------------


KevinR
Veteran


Jun 23, 2009, 8:35 AM

Post #27 of 36 (7159 views)
Re: [namishtiwari] perl script help [In reply to] Can't Post

I see this line in your code, there is no initial condition/value for $index


Code
for(;$index<@records;$index++)

-------------------------------------------------


perlisgreat
Novice

Jun 23, 2009, 8:43 AM

Post #28 of 36 (7156 views)
Re: [KevinR] perl script help [In reply to] Can't Post

This is because i want to iterate after the inial loop. If i have initial value then everytime it will start looping from the beginning of the file.


FishMonger
Veteran / Moderator

Jun 23, 2009, 8:43 AM

Post #29 of 36 (7156 views)
Re: [KevinR] perl script help [In reply to] Can't Post


In Reply To
change lines like this:


Code
for($index=0;$index<@records;$index++)


change to:


Code
for(my $index=0;$index<@records;$index++)


see if that clears up all or nearly all the errors about packaging "$index"


Don't you think this would be cleaner?

Code
for my $index ( 0 .. $#records )

or

Code
for my $index ( 0 .. @records - 1 )



FishMonger
Veteran / Moderator

Jun 23, 2009, 8:45 AM

Post #30 of 36 (7155 views)
Re: [namishtiwari] perl script help [In reply to] Can't Post


In Reply To
Hi,

I was able to solve this problem and the code is working fine now. i am not using these statements in my code

Code
 
use strict;
use warnings;



Ignoring problems instead of fixing them is not a very good solution.


FishMonger
Veteran / Moderator

Jun 23, 2009, 8:51 AM

Post #31 of 36 (7152 views)
Re: [FishMonger] perl script help [In reply to] Can't Post

We could make it even better/cleaner by not using the index.


Code
foreach my $record ( @records )



KevinR
Veteran


Jun 23, 2009, 9:10 AM

Post #32 of 36 (7150 views)
Re: [FishMonger] perl script help [In reply to] Can't Post

Do I think it would be cleaner? Yes, for sure. Do I think I want to suggest that to the OP? No. Wink

Plus he is getting help on unix.com from other people with the same question. Its almost to the point of "too many cooks spoiling the soup".
-------------------------------------------------


(This post was edited by KevinR on Jun 23, 2009, 10:50 AM)


FishMonger
Veteran / Moderator

Jun 23, 2009, 9:17 AM

Post #33 of 36 (7146 views)
Re: [KevinR] perl script help [In reply to] Can't Post

Personally, I think the only time the C style for loop should used is when the iterator needs to change by a value other than 1.

If the C style is going to be used, then at least you should add some whitespace to make it more readable.


Code
for ( my $index = 0;  $index < @records;  $index++ )



KevinR
Veteran


Jun 23, 2009, 10:51 AM

Post #34 of 36 (7139 views)
Re: [FishMonger] perl script help [In reply to] Can't Post


In Reply To
Personally, I think the only time the C style for loop should used is when the iterator needs to change by a value other than 1.

If the C style is going to be used, then at least you should add some whitespace to make it more readable.


Code
for ( my $index = 0;  $index < @records;  $index++ )



I think you're preaching to the choir Fish. Shocked <-- me singing
-------------------------------------------------


perlisgreat
Novice

Jun 29, 2009, 7:37 AM

Post #35 of 36 (7085 views)
Re: [KevinR] perl script help [In reply to] Can't Post

Hi Larry,

here is my piece of code,


Code
 

#!/usr/bin/perl
use Getopt::Long;
my $result;
my $Summary;
my $Individual;
my $Diagnostics;
my $All;
my $help;

$result = GetOptions ("LogDir=s" => \$LogDir,
"Logfile=s" => \$Logfile,
"Summary" => \$Summary,
"Indiviual=s" => \$Individual ,
"Diagnostics=s" => \$Diagnostics,
"All" => \$All,
"help" => \$help);


sub usage_help
{
printf <<EOF
Script usage is
Scriptname --Summary
Scriptname --Indiviual=Arcotid/QNA/OTP/Password/All/Arcotid Revoke/Expire/All/QNA number
Scriptname --Diagnostics=username/system
Scriptname --ALL
EOF


}
usage_help() if($help);
usage_help() unless($Logfile);

if($Summary)
{
Total_Number_Of_Transactions() ;
}




sub Total_Number_Of_Transactions
{
my $logfile = $Logfile;
my $logDir = $ARGV[1];
my $logPrefix = $ARGV[2];
#die "usage: $0 <logDir> <logPrefix>" unless $logDir and $logPrefix;
die "Log dir $logDir doesn't exist" unless -d "$logDir";
for my $logFile ( glob("$logDir/${logPrefix}*") )
{
open($log, "<", $logFile) or die "Can't open $logFile for reading.";
open(FP_OUT,">total_transactions") or die "cannot create file total_transactions for writing";
}

my $Total_QnA_Count = 0;
my $Total_OTP_Count = 0;
my $Total_UP_Count = 0;
my $Total_ArcotID_Count = 0;
my $Success_QnA_Count =0;
my $Failure_QnA_Count = 0;
my $Success_ArcotID_Count = 0;
my $Failure_ArcotID_Count = 0;
my $Success_OTP_Count = 0;
my $Failure_OTP_Count = 0;
my $Success_UP_Count = 0;
my $Failure_UP_Count = 0;

OUTER: while( $line = <$log> )
{
$line =~ tr/\r\n//d;
if ($line =~ /Arcot Native Server: recvd AA_BIN_MSG_VER_CHG/)
{
while ($line = <$log>)
{
if ($line =~ /ArcotID\s*Auth\s*SUCCESS.*/)
{
$Success_ArcotID_Count++;
next OUTER;
}
elsif ($line =~ /Auth failed.*/)
{
$Failure_ArcotID_Count++;
next OUTER;
}

}
}
if ($line =~ /QNA Step - AUTH IN PROGRESS/)
{
while ($line = <$log>)
{
if ($line =~ /QNA Auth - Success.*/)
{
$Success_QnA_Count++;
next OUTER;
}
elsif ($line =~ /Message: QNA Auth Failed.*/)
{
$Failure_QnA_Count++;
next OUTER;
}

}
}
if ($line =~ /Entering OTPAuthModule::authenticate/)
{
while ($line = <$log>)
{
if ($line =~ /OTP SUCCESS.*/)
{
$Success_OTP_Count++;
next OUTER;
}
elsif ($line =~ /Message: OTP FAILED.*/)
{
$Failure_OTP_Count++;
next OUTER;
}

}
}
if ($line =~ /Entering UPAuthModule::authenticate/ .. /Sending Invalid credential/)
{
while ($line = <$log>)
{
if ($line =~ /UPAuth SUCCESS.*/)
{
$Success_UP_Count++;
next OUTER;
}
elsif ($line =~ /UPAuth FAILED.*/)
{
$Failure_UP_Count++;
next OUTER;
}

}
}
}

$Total_ArcotID_Count = $Success_ArcotID_Count + $Failure_ArcotID_Count ;
$Total_QnA_Count = $Success_QnA_Count + $Failure_QnA_Count ;
$Total_OTP_Count = $Success_OTP_Count + $Failure_OTP_Count ;
$Total_UP_Count = $Success_UP_Count + $Failure_UP_Count ;
printf FP_OUT "Total ArcotID count is $Total_ArcotID_Count\n";
printf FP_OUT "Total QnA count is $Total_QnA_Count\n";
printf FP_OUT "Total OTP count is $Total_OTP_Count\n";
printf FP_OUT "Total User Password count is $Total_UP_Count\n";
close(FP_OUT);
close($log);

}

i am accessing this as--


Quote
C:\Perl Script\Sample Programs>perl sample2.pl --Summary --LogDir="C:\Perl Scrip\Sample Programs" --Logfile=arcotwebfort_20May09
Log dir doesn't exist at sample2.pl line 48.

I got the above error when i ran like that. I tried with putting (.) also in place of directory name but no luck.

Am i accessing the files correctly.
One more thing i would like to ask is--

the does not give me correct out when i ran it without getopt::long. And now it is not compiling.

Can you suggest me what is wrong here.
What modifications i need to do to get rid of this problem.

Thanks
NT


perlisgreat
Novice

Jun 30, 2009, 8:30 AM

Post #36 of 36 (7062 views)
Re: [namishtiwari] perl script help [In reply to] Can't Post

Hi,

I got the problem solved.

I have one other query.



Here is my piece of code--


Code
main(); 
sub main
{
$result = GetOptions ("LogDir=s" => \$LogDir,
"Summary" => \$Summary,
"Indiviual=s" => \$Individual ,
"Diagnostics=s" => \$Diagnostics,
"Prefix=s" => \$Prefix,
"All" => \$All,
"help" => \$help);
usage_help() if($help);
usage_help() unless($Prefix);
usgage_help() unless($LogDir);

if($LogDir)
{
die "Log dir '$LogDir' doesn't exist" unless -d $LogDir;
}

$glob_path = "$LogDir/${prefix}*";
@log_paths = glob $glob_path or die "No files found in '$glob_path'";
printf "log files = \n";
print @log_paths;
printf "\n";

if($Summary)
{
process_summaryreport ();
}

if($Individual)
{
if($Individual == "ArcotID")
{
ArcotID_Authentication(@log_paths);
}
}
}


I am calling the script as--

Code
C:\Perl Script>perl summaryreport_latest_working.pl --LogDir=. --Prefix=arcotweb --Individual=ApricotID


It does not show me any output.
I think the problem lies here but not sure.

Code
if($Individual) 
{
if($Individual eq "ArcotID")
{
ArcotID_Authentication(@log_paths);
}
}
[/code>]
Individual can take diffrent arguements one of them is ApricotID, other may be QnA and OTP or all, so depending on the arguement i want to call the respective function.



Thanks
NT

First page Previous page 1 2 Next page Last page  View All
 
 


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

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