Solved

Perl Time Stamp Calculation

Posted on 2009-05-05
4
1,334 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 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
Six Sigma Control Plans

726 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