Sponsored Content
Full Discussion: Date problem in perl
Top Forums Shell Programming and Scripting Date problem in perl Post 302335549 by namishtiwari on Monday 20th of July 2009 02:47:31 AM
Old 07-20-2009
Quote:
Originally Posted by BubbaJoe
Looks like the error is coming from this line. Can you post the code around this line please.
Code:
DateTime::new('undef', 'year', 'undef', 'month', 'undef', 'day', 'undef'
, 'hour', 'undef', ...) called at WFLogStat.pl line 372


This is the code around the problem,

Code:
sub avg_time_taken_in_UP
{
	
	die if not @_;
	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' for reading."; 
		printf AVG_OUT "Processing file $log_file...\n"; 
		while( <$log> ) 
		{ 
			    s{\s+\z}{};
				if (/(?:Entering|Exiting) UPAuthModule::authenticate/) 
				{
					$end_dt = '';
					my @dtA = split;
					my @time = split /[:.]/, $dtA[3];
					( /Exiting/ ? $end_dt : $start_dt ) = DateTime->new
					(
					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)
				{
					print AVG_OUT "start: ", $start_dt, "\n";
					print AVG_OUT "end: ",   $end_dt,   "\n";
					my $e = $end_dt->subtract_datetime($start_dt);
					printf	AVG_OUT "elapsed time for User Password Module: %s year(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);
	
		
}

Thanks
Namish

 

8 More Discussions You Might Find Interesting

1. Programming

Date time problem while executing perl script.

Hi All, This Monday 15th March 2010, i have faced a weired issue with my Perl script execution, this script is scheduled to run at 1 minute past midnight on daily basis ( 00:01 EST ) generally for fetching previous business date , say if it is Monday it should give last Friday date, for Tuesday... (0 Replies)
Discussion started by: ravimishra
0 Replies

2. Shell Programming and Scripting

problem with date in perl

hi guys, i have a variable date that stores the current date....now i need to subtract 2 minutes from it...can someone tell me how to do it in perl.... (5 Replies)
Discussion started by: niteesh_!7
5 Replies

3. Shell Programming and Scripting

Problem with date in perl!!

Hi All, I am facing an issue with perl.. I have a perl script that executes the stored procedure and puts the data in a file. In stord proc we have one date column also. In table from which it is fetching the data, date is in the form "14/03/2010 00:00:00.000" (DD/MM/YYYY). But when the perl... (4 Replies)
Discussion started by: abhisharma23
4 Replies

4. Programming

Problem with perl pattern for date

Hello Friends, I have been struck with a perl script for quite some time now. I have a log file which gives a date which is sometimes coming in this format Script /opt/OV/bin/OpC/agtinstall/inst.sh invoked by root at 02/25/11 15:12:50 or sometimes in this format Script... (2 Replies)
Discussion started by: achak01
2 Replies

5. Shell Programming and Scripting

Need to capture dates between start date and end date Using perl.

Hi All, Want to get all dates and Julian week number for that date between the start date and end date. How can I achive this using perl? (To achive above functionality, I was connecting to the database from DB server. Need to execute the same script in application server, since databse... (6 Replies)
Discussion started by: Nagaraja Akkiva
6 Replies

6. Shell Programming and Scripting

Extract week start,end date from given date in PERL

Hi All, what i want to do in perl is i should give the date at run time .Suppose date given is 23/12/2011(mm/dd/yyyy) the perl script shold find week start date, week end date, previous week start date,end date,next week start date, end date. In this case week start date will be-:12/19/2011... (2 Replies)
Discussion started by: parthmittal2007
2 Replies

7. Shell Programming and Scripting

Fetch date of 7 years back from current date in Perl

$beginDate = substr(DateCalc("today", "-7Days"),0,8); This fetches the date 7 days back Can I fetch the date before 7 years from todays date in Perl using same syntax Use code tags, see PM. (3 Replies)
Discussion started by: parthmittal2007
3 Replies

8. Shell Programming and Scripting

Problem in passing date to external function from perl script.

my $sysdate = strftime('%Y-%m-%d', localtime ); biDeriveByDate('Table_Str',$sysdate,\@lIndx,\@lResVals) In a perl script, when I'm trying to pass $sysdate to some external function it's not working since $sysdate is passed as a string mentioned above but my function is expecting a date value... (1 Reply)
Discussion started by: Devesh5683
1 Replies
File::CheckTree(3pm)					 Perl Programmers Reference Guide				      File::CheckTree(3pm)

NAME
File::CheckTree - run many filetest checks on a tree SYNOPSIS
use File::CheckTree; $num_warnings = validate( q{ /vmunix -e || die /boot -e || die /bin cd csh -ex csh !-ug sh -ex sh !-ug /usr -d || warn "What happened to $file? " }); DESCRIPTION
The validate() routine takes a single multiline string consisting of directives, each containing a filename plus a file test to try on it. (The file test may also be a "cd", causing subsequent relative filenames to be interpreted relative to that directory.) After the file test you may put "|| die" to make it a fatal error if the file test fails. The default is "|| warn". The file test may optionally have a "!' prepended to test for the opposite condition. If you do a cd and then list some relative filenames, you may want to indent them slightly for readability. If you supply your own die() or warn() message, you can use $file to interpolate the filename. Filetests may be bunched: "-rwx" tests for all of "-r", "-w", and "-x". Only the first failed test of the bunch will produce a warning. The routine returns the number of warnings issued. AUTHOR
File::CheckTree was derived from lib/validate.pl which was written by Larry Wall. Revised by Paul Grassie <grassie@perl.com> in 2002. HISTORY
File::CheckTree used to not display fatal error messages. It used to count only those warnings produced by a generic "|| warn" (and not those in which the user supplied the message). In addition, the validate() routine would leave the user program in whatever directory was last entered through the use of "cd" directives. These bugs were fixed during the development of perl 5.8. The first fixed version of File::CheckTree was 4.2. perl v5.18.2 2014-01-06 File::CheckTree(3pm)
All times are GMT -4. The time now is 02:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy