The result of timelocal will depend on the local time zone. For example, when I ran your code it printed 18123 because I'm at GMT-0500. Of course, that can be avoided by using gmtime insead. The following code prints the expected 3723:
use Time::Local; my ($hours, $minutes, $seconds) = (1, 2, 3); #insert your regex here print timegm($seconds, $minutes, $hours, 1, 0, 70);
Unfortunately, even that's not a complete solution, because the epoch is not Jan 1, 1970 on all platforms. On the Macintosh, for example, it's Jan 1, 1904, and the output is 2082830523.

There's still a way to do it with timelocal, though:

use Time::Local; my ($hours, $minutes, $seconds) = (1, 2, 3); #insert your regex here print timelocal($seconds, $minutes, $hours, 1, 0, 100) - timelocal(0, 0, 0, 1, 0, 100);
The choice of year is relatively arbitrary, but note that you mustn't pick a time of year that will be affected by daylight savings.

So, you can solve this problem using Time::Local, you just have to be careful about how you do it.


In reply to Re: Re: Time to seconds by chipmunk
in thread Time to seconds by argus

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.