You might try er -- I mean it seems right that you are using Time::Local -- granting that you are actually going to be reading date/time strings from a file, and it'll be easy for you to parse that into separate scalars (without worrying so much about checking for correctness of the input).
NAME
Time::Local - efficiently compute time from local and GMT time

SYNOPSIS
$time = timelocal($sec,$min,$hour,$mday,$mon,$year);
$time = timegm($sec,$min,$hour,$mday,$mon,$year);

DESCRIPTION
These routines are the inverse of built-in perl functions localtime() and gmtime()...

update: OOPS. Sorry I didn't look more closely at your code before posting. Anyway, I think there's nothing wrong with using Time::Local -- it does exactly what you want in this case.

another update: One nice thing I learned about Time::Local -- you can give it scalar values that equate to things like "Feb 30 2001", and it does the "right" thing, in the sense of returning the time in terms of "two days after Feb 28 2001". This came in very handy when I had to do some date arithmetic -- e.g. determine month and day of month for "day before" or "day after" a given date, or some number of hours before or after a given time. (This was some years ago, before I learned about Date::Manip -- or maybe before that module even existed.)


In reply to Re: scalar localtime() to timestamp by graff
in thread scalar localtime() to timestamp by jonnyfolk

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.