namishtiwari has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, Thanks for the valueable information. I need ur help in one more problem i am facing right now-- here is my piece of code-
use DateTime; sub Avg_Time_Taken_Per_Transaction { avg_time_taken_in_QnA(@log_paths); } sub avg_time_taken_in_QnA { print "in avg_time_taken_in_QnA\n"; die if not @_; print "@_\n"; my @log_files = @_; open(AVG_OUT,">avg_time") or die "cannot create file avg_time for +writing"; my %mon2num = qw( Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun 6 Jul 7 Aug 8 Sep 9 Oct 10 Nov 11 Dec 12 ); my ( $start_dt, $end_dt ); for my $log_file (@log_files) { open my $log, '<', $log_file or die "Can't open '$log_file' fo +r reading."; printf AVG_OUT "Processing file $log_file...\n"; while( <$log> ) { s{\s+\z}{}; #m/^\s*\w+\s+(\w+)\s+(\d+)\s+(\d\d:\d\d:\d\d\.\d\d\d)\s+(\ +d+)\s+..*pid\s+(\d+)\s+tid\s+(\d+):..*RiskServer : Read.*/i) if (/(?:Entering|Exiting) QnAModule::authenticate/) { $end_dt = ''; my @dtA = split; my @time = split /[:.]/, $dtA[3]; ( /Exiting/ ? $end_dt : $start_dt ) = DateTime->ne +w( year => $dtA[4], month => $mon2num{ $dtA[1] }, day => $dtA[2], hour => $time[0], minute => $time[1], second => $time[2], nanosecond => $time[3], ); if ($end_dt && $start_dt) { printf AVG_OUT "start: ", $start_dt, "\n"; printf AVG_OUT "end: ", $end_dt, "\n"; my $e = $end_dt->subtract_datetime($start_dt); printf AVG_OUT "elapsed time for QnA Module: %s yea +r(s), %s month(s), %s week(s), %s day(s), %s hour(s), %s min, %s sec, + %s ms\n", $e->years, $e->months, $e->weeks, $e->days, $e->hours, $e->minutes, $e->seconds, $e->nanoseconds; } } } close $log or warn; } close (AVG_OUT); }
I am calling the function sub Avg_Time_Taken_Per_Transaction in a condition and that is -
sub process_summaryreport { printf "in process summary\n"; Avg_Time_Taken_Per_Transaction (@log_paths); } [/code] The snippet of the logfile is-- <quote> Tue May 19 23:25:13.306 2009 Morocco Standard Time INFO: pid 2172 t +id 3124: 160: 10086900: Entering QnAModule::authenticate Tue May 19 23:25:13.306 2009 Morocco Standard Time INFO: pid 2172 t +id 3124: 160: 10086900: QnA Session Id :[1:10086900] Tue May 19 23:25:13.306 2009 Morocco Standard Time INFO: pid 2172 t +id 3124: 160: 10086900: QNA Step - AUTH IN PROGRESS Tue May 19 23:25:13.306 2009 Morocco Standard Time INFO: pid 2172 t +id 3124: 160: 10086900: Session tracker Id associated with QnA challe +nge(auth round questions) : [1:10086885] Tue May 19 23:25:13.306 2009 Morocco Standard Time INFO: pid 2172 t +id 3124: 160: 10086900: User DB Query Details: Tue May 19 23:25:13.306 2009 Morocco Standard Time INFO: pid 2172 t +id 3124: 160: 10086900: userName :[] Tue May 19 23:25:13.306 2009 Morocco Standard Time INFO: pid 2172 t +id 3124: 160: 10086900: Group ID :1020 Tue May 19 23:25:13.306 2009 Morocco Standard Time INFO: pid 2172 t +id 3124: 160: 10086900: User ID :5526 Tue May 19 23:25:13.306 2009 Morocco Standard Time INFO: pid 2172 t +id 3124: 160: 10086900: Number of rows fetched from DB : 1 Tue May 19 23:25:13.306 2009 Morocco Standard Time INFO: pid 2172 t +id 3124: 160: 10086900: Err[115261735], Message: Native Verification: + ANSWER(s) MISMATCH! (correct/total : 1/2)! Tue May 19 23:25:13.306 2009 Morocco Standard Time INFO: pid 2172 t +id 3124: 160: 10086900: Err[115261735], Message: QNA Auth Failed(Inva +lid Credentials), Repeating the challenge and Returning FAILED Tue May 19 23:25:13.306 2009 Morocco Standard Time INFO: pid 2172 t +id 3124: 160: 10086900: Exiting QnAModule::authenticate </quote> When i ran the program like this-- <code> Processing file C:/Perl Script/Sample Programs/arcotwebfort_29May09_19 +_17_47.log ... Warning: something's wrong at summaryreport_latest_working_latest.pl l +ine 643. in Total_Number_Of_Transactions in avg_time_taken_in_QnA C:/Perl Script/Sample Programs/arcotwebfort_20May09_00_03_55.log C:/Pe +rl Script/ Sample Programs/arcotwebfort_20May09_15_12_18.log C:/Perl Script/Sampl +e Programs /arcotwebfort_20May09_23_32_56.log C:/Perl Script/Sample Programs/arco +twebfort_2 9May09_18_29_45.log C:/Perl Script/Sample Programs/arcotwebfort_29May0 +9_19_17_47 .log in avg_time_taken_in_OTP in avg_time_taken_in_UP The 'hour' parameter (undef) to DateTime::new was an 'undef', which is + not one o f the allowed types: scalar at C:/Perl/lib/Params/ValidatePP.pm line 634 Params::Validate::__ANON__('The \'hour\' parameter (undef) to +DateTime:: new was an \'unde...') called at C:/Perl/lib/Params/ValidatePP.pm line + 485 Params::Validate::_validate_one_param('undef', 'HASH(0x1e3dc2c +)', 'HASH( 0x1d391c8)', 'The \'hour\' parameter (undef)') called at C:/Perl/lib/P +arams/Vali datePP.pm line 345 Params::Validate::validate('ARRAY(0x1c2cde4)', 'HASH(0x1d3933c +)') called at C:/Perl/lib/DateTime.pm line 171 DateTime::new('undef', 'year', 'undef', 'month', 'undef', 'day +', 'undef' , 'hour', 'undef', ...) called at summaryreport_latest_working_latest. +pl line 36 9 main::avg_time_taken_in_UP('C:/Perl Script/Sample Programs/arc +otwebfort_ 20May09_00_03_55.log', 'C:/Perl Script/Sample Programs/arcotwebfort_20 +May09_15_1 2_18.log', 'C:/Perl Script/Sample Programs/arcotwebfort_20May09_23_32_ +56.log', ' C:/Perl Script/Sample Programs/arcotwebfort_29May09_18_29_45.log', 'C: +/Perl Scri pt/Sample Programs/arcotwebfort_29May09_19_17_47.log') called at summa +ryreport_l atest_working_latest.pl line 233 main::Avg_Time_Taken_Per_Transaction('C:/Perl Script/Sample Pr +ograms/arc otwebfort_20May09_00_03_55.log', 'C:/Perl Script/Sample Programs/arcot +webfort_20 May09_15_12_18.log', 'C:/Perl Script/Sample Programs/arcotwebfort_20Ma +y09_23_32_ 56.log', 'C:/Perl Script/Sample Programs/arcotwebfort_29May09_18_29_45 +.log', 'C: /Perl Script/Sample Programs/arcotwebfort_29May09_19_17_47.log') calle +d at summa ryreport_latest_working_latest.pl line 182 main::process_summaryreport('C:/Perl Script/Sample Programs/ar +cotwebfort _20May09_00_03_55.log', 'C:/Perl Script/Sample Programs/arcotwebfort_2 +0May09_15_ 12_18.log', 'C:/Perl Script/Sample Programs/arcotwebfort_20May09_23_32 +_56.log', 'C:/Perl Script/Sample Programs/arcotwebfort_29May09_18_29_45.log', 'C +:/Perl Scr ipt/Sample Programs/arcotwebfort_29May09_19_17_47.log') called at summ +aryreport_ latest_working_latest.pl line 84 main::main() called at summaryreport_latest_working_latest.pl +line 57
I am not able to interpret this. Do you have any other suggestion in this regard. Or any other approach. KIndly suggest me something in this.. Thanks NT

Replies are listed 'Best First'.
Re: date problem
by ikegami (Patriarch) on Jul 09, 2009 at 16:55 UTC

    The 'hour' parameter (undef) to DateTime::new was an 'undef'

    It's telling you that $time[0] is undef.

    That would happen if $dtA[3]'s value contained neither ":" nor ".".

    Make sure $dtA[3] contains what you think it does.

    I can't replicate the problem with what you gave me, even after fixing Avg_Time_Taken_Per_Transaction.

    Update: Added last paragraph.

      Can you suggest me what changes you did to fix the problem in Avg_Time_Taken_Per_Transaction();I get the output in one output file but when i execute on command line i get those errors. Thanks NT
        Changed avg_time_taken_in_QnA(@log_paths); to avg_time_taken_in_QnA(@_);. It was ignoring the arguments passed to it by process_summaryreport, referencing an undeclared variable instead. I doubt that was the cause of your problem.
Re: date problem
by mzedeler (Pilgrim) on Jul 09, 2009 at 20:12 UTC
    use strict; use warnings;

    Repost new question here when you have done that, run the program and fixed any errors or warnings that may have arised.

Re: date problem
by ikegami (Patriarch) on Jul 09, 2009 at 16:49 UTC

    The 'hour' parameter (undef) to DateTime::new was an 'undef'

    It's telling you that $time[0] is undef.

    That would happen if $dtA[3]'s value contained neither ":" nor ".".

    Make sure $dtA[3] contains what you think it does.