my $first = "00:00:01:04";
my $last = "00:00:08:861";
my $output = $first-$last;
... the values of both $first and $last 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.
|