Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Timer subtraction

by sundialsvc4 (Abbot)
on Oct 06, 2017 at 12:21 UTC ( #1200822=note: print w/replies, xml ) Need Help??

in reply to Timer subtraction

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 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.

Replies are listed 'Best First'.
Re^2: Timer subtraction
by Anonymous Monk on Jan 15, 2018 at 12:45 UTC
    Restate things stated already and not answer question answered months ago.... classic pretender

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1200822]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2018-08-15 13:02 GMT
Find Nodes?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:

    Results (160 votes). Check out past polls.