in reply to function to add time
#!/usr/bin/perl -wl use strict; my $time1 = '12:30:36'; my $time2 = '12:45:03'; print sum_times($time1, $time2); sub sum_times { my $secs; for (@_) { chomp; my ($h, $m, $s) = split /:/; $secs += ($h*3600 + $m*60 + $s); } return sec_to_hms($secs); } sub sec_to_hms { use integer; local $_ = shift; my ($h, $m, $s); $s = $_ % 60; $_ /= 60; $m = $_ % 60; $_ /= 60; $h = $_; return sprintf("%02d:%02d:%02d",$h, $m, $s); }
Notes:
Cheers,
Darren
|
|---|