Thank You.
When i ran the script like this it gave me error--
C:\Perl Script>perl timediff.pl logfile
Use of uninitialized value in print at timediff.pl line 35, <LF> line 17.
start:
end: 2009-04-26T04:06:05
Can't call method "time_zone" on an undefined value at C:/Perl/lib/DateTime.pm l
ine 1231, <LF> line 17.
I put the DateTime module files in Perl Librray.
logfile is also in the directory where i am running the program.
Thank You very much for looking into my problem and providing me the script. I tested it and it worked fine means it executed well without any error. I need to verify the time diffrences here and let you know.
I want to know some explanation here---
my $logfile = shift || die "usage: $0 <filename>\n";
What is the use of shift here, later part of the (OR ||) i know.
my ( $start_dt, $end_dt );
Is this fuction parameters. It does not have any name.
If the first argument passed to the script (i.e. the value returned by the shift function) is true in boolean context,
assign that value to the variable logfile, otherwise exit with error. If you name your input file 0, the code above wont work
This is just a declaration, it's the same as:
my $start_dt;
my $end_dt;
Assign the list returned by the splitting of the $_ variable to the array dtA (date Array). split by default splits on whitespace (after skipping any leading whitespace).
It's the ternary operator: expression ? if true evaluate this:if false evaluate that.
If the current input record ($_) matches the pattern in // assign the returned object to the reference $end_dt, otherwise assign it to the reference $start_dt.
Yes, subtract_datetime is one of the available methods in the DateTime class.