If we take the OP as literally written:
my $first = "00:00:01:04";
my $last = "00:00:08:861";
my $output = $first-$last;
... the values of both $first
are quite-clearly strings.
In order to do arithmetic against them, they must be converted to a numeric form. There are many, many libraries in the CPAN library
that are concerned with time, and some of these are built in to the Core so as to be immediately available without installing.
For instance, DateTime takes the now-common approach of treating a date/time as a Perl object. You create one, either specifying a string to be decoded or the individual parts of a time, then you can simply manipulate it using the methods provided.
In this particular case, where a string-format might not be automagically recognized on its own, you might need to break-apart the four parts of the string (e.g. with split() so that you can instantiate the object with the pieces-of-interest as shown in the documentation for DateTime:
my $dt = DateTime->new(
year => 1966,
month => 10,
day => 25,
hour => 7,
minute => 15,
second => 47,
nanosecond => 500000000,
time_zone => 'America/Chicago',
You have a rich choice of time-handling modules at your disposal which will take care of all of the niggling problems associated with time encoding/decoding and time-arithmetic.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||