I could always multiply the first number by 60x60...

Well hey, why not?

sub seconds { if( $_[0] =~ /^(\d+):(\d+):(\d+)$/ ) { return ($1 * 60 + $2) * 60 + $3; } else { return 0; } }

Look how much time you just saved :) Or is there a deeper issue involved?

update: looking at jeffa's solution underscores what I mean. Not that his solution is bad, but you have to spend the time to find, download and install the module. Then you have to memorise the % parameters. Each time I need to use strfptime, I'll have to call up the man page. For simple uses like this, that's going to be a net loss.

There's Lazy and Lazy, and I'm not sure that the module approach is a win here. Doing what you did saved you the most time, and let you get on with the rest. It's much faster to bang out the above code (although one should not underestimate the fact that the module should have regression tests that cover what you're using it for).


In reply to Re: perl time conversion (seconds) by grinder
in thread perl time conversion by markd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.