GhodMode, there is a subtle race-condition in your example. Since you are calling localtime twice, it could potentially return two different values. For instance, say you ran the code right as the clock struck ten:

my $current_hour = strftime( "%H", localtime() ); # say it's 9:59, so +"9" is returned. # ... your process is switched off the processor... my $current_minute = strftime( "%M", localtime() ); # now it's 10:00, +so "00" is returned.
Now your code would act as if it's 9:00pm, when in fact it's 10:00pm. Not trying to nit-pick, but I just couldn't help noticing... ;-)

If it were me, I would keep the "closing time" in 24-hour format (I realize the OP doesn't in his/her example) and completely forgo the use of strftime:

#my $store_close = "7:05 PM"; my $store_close = "19:05"; my ($close_hour, $close_minute) = split( /:/, $store_close ); my ($current_minute, $current_hour) = (localtime)[1,2];


In reply to Re^2: Comparing a string value's time with the computers time by crashtest
in thread Comparing a string value's time with the computers time by Anonymous Monk

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.