?
Solved

Perl Time Stamp Calculation

Posted on 2009-05-05
4
Medium Priority
?
1,337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 1600 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 400 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Six Sigma Control Plans
Suggested Courses

766 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