I wanted to find out how long a particular operatiion, such asa backup, took to execute. I also wanted the number of hours, minutes and seconds, not just the seconds. This subroutine will return a string like this: 02:33:59 There's probably a better way, I just couldn't find one...
sub get_et { my $et = shift; my ($days,$hours,$minutes,$seconds,$dstr); my $sec = 1; my $min = $sec * 60; my $hour = $min * 60; my $day = $hour * 24; $et -= ($day * $days) if $days = int($et / $day); $et -= ($hour * $hours) if $hours = int($et / $hour); $et -= ($min * $minutes) if $minutes = int($et / $min); $seconds = $et; $dstr = sprintf(qq{$days Day%s, }, $days > 1 ? 's' : '') if $days; $et = sprintf(qq{%.2d:%.2d:%.2d},$hours,$minutes,$seconds); return $dstr . $et; }

Replies are listed 'Best First'.
Re: getting the elapsed time
by damian1301 (Curate) on Feb 25, 2001 at 09:19 UTC
    NOTE: I obviously misread when I posted...he/she said time when I though he/she meant date. I hope the modules I posted below help or just /msg me and tell me then reap this node

    As a matter of fact, there is a better way.

    With a really quick search through the CPAN I came up with these two, very efficient and optionful, modules.Some people might say that these are clunky and slow...I'll leave that to your own judgement

    Hope that helps you. Also, you can get various formats in these modules (eg. 2/24/01 and so on) so you don't have to stick with that ugly one :)

    Almost a Perl hacker.
    Dave AKA damian

    I encourage you to email me