Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1200822]
help
Chatterbox?
and the universe expands...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2018-04-24 17:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?