Solved

Perl Time Stamp Calculation

Posted on 2009-05-05
4
1,327 Views
Last Modified: 2012-05-06
I have a file that contains start and end times for processes:
     Start BatPrcsDrvr.pl CAEXPENS 1    2009-05-05 01:05:52
     End BatPrcsDrvr.pl CAEXPENS 1 Successfully    2009-05-05 01:05:53
     Start BatPrtnDrop.pl CAEXPENS 1    2009-05-05 01:06:12
     End BatPrtnDrop.pl CAEXPENS 1 Successfully    2009-05-05 01:15:29
     Start BatBackup.pl CAEXPENS 1    2009-05-05 01:21:11
     End BatBackup.pl CAEXPENS 1 Successfully    2009-05-05 01:25:57
etc.
I want to take the time stamp on the End line and compare it to the time stamp on the start line to get the elapsed time.  I am working on this now but not getting very far so any tips would be appreciated.  I will repost if I figure it out first.
0
Comment
Question by:Angela_Wilcox
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 400 total points
ID: 24307147
use  Time::Local;
$_='Start BatPrcsDrvr.pl CAEXPENS 1    2009-05-05 01:05:52';
@d=/(\d+)-(\d+)-(\d+)\s+(\d+):(\d+):(\d+)/;
$timestamp = timelocal(@d[5,4,3,2],$d[1]-1,$d[0]);

0
 

Author Comment

by:Angela_Wilcox
ID: 24307395
Epoch time conversion  - Exactly what was needed...
0
 
LVL 5

Assisted Solution

by:vikaskhoria
vikaskhoria earned 100 total points
ID: 24312471
You can also use the CPAN, Date::Manip modules to manipulate date. This also handles text having dates.

See:
http://search.cpan.org/~sbeck/Date-Manip-5.54/lib/Date/Manip.pod
0
 

Author Comment

by:Angela_Wilcox
ID: 24313640
Although the Date:: Manip could probably also do what I needed - I took the first authors comments and created a function then imbedded this into my output as follows - this is in a while loop that does other stuff as well but thought I would show how I used the solution - thanks to both of you for your help.

print $fh_output_time_log ("$_", " ", &epoch_time($_) ," \n");

sub epoch_time
{
    local @_;
    @d=/(\d+)-(\d+)-(\d+)\s+(\d+):(\d+):(\d+)/;
    return(sprintf(timelocal(@d[5,4,3,2],$d[1]-1,$d[0])));
}
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question