Try the Date::Manip module:
use Date::Manip::Date; my $base = Date::Manip::Date->new; for my $deltastr ("32:05", "11:32:05") { $delta = $base->new_delta($deltastr); $deltasec = $delta->printf("%sys"); print "$deltastr => $deltasec s\n"; } =begin output 32:05 => 1925 s 11:32:05 => 41525 s =end output =cut
Update: this is incorrect, for it doesn't work for times greater than a day that ps outputs, eg. "35-04:04:09". I guess there's no simpler workaround other than separating the fields (or at least the day field) manually using a regex.
In reply to Re: A regular expression that will work for (hh:)mm:ss [converting clock time to seconds]
by ambrus
in thread A regular expression that will work for (hh:)mm:ss [converting clock time to seconds]
by aware74
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |