First of all, have you seen how Perlmonks tries to format your log file example? Maybe you should put your log file inside code tag as well.

Secondly, and more relevant to your question, your variable $yesterday contains the time it was exactly 24 hours ago. Yesterday contained 24 * 60 * 60 = 86400 seconds, and $yesterday covers exactly one of those - therein lies the basis of your problem.

One way (of many) to solve this, is to calculate two values - $yesterday_start and $yesterday_end, and then check if the time stamp of the line in the log file lies between these two values. DateTime might prove useful. But beware of edge cases such as those days that switch from or to DST and other tricky business like that.

Another way could be to take $yesterday the way you do it now, and strip off the time information so that you only hold the date information. That's probably the easiest, because except for the way you obtaini $yesterday your code can run unaltered. But again, be careful that you don't run into problems on days that DST ends.

And finally, these days the three-arguments open (which you already use) with lexical filehandles is recommended. See perldoc open.


In reply to Re: counting yesterdays hits in a logfile by muba
in thread counting yesterdays hits in a logfile by jrp370

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.