Perhaps the following will help:

use strict; use warnings; use Time::Piece; use Time::Seconds qw(ONE_DAY); my $yesterday = localtime() - ONE_DAY(); my $mergedYesterday = join '/', ( split ' ', $yesterday )[ 2, 1, 4 ]; while (<DATA>) { my ($date) = /\[([^:]+)/; # Capture date, e.g., 11/Nov/2012 $date =~ s/^0//; # Remove leading zero: 08/Oct/2007 -> 8/Oct/2007 print if $date eq $mergedYesterday; } __DATA__ 66.249.65.107 - - [11/Nov/2012:19:33:01 -0400] "GET /support.html HTTP +/1.1" 200 11179 111.111.111.111 - - [11/Nov/2012:19:33:01 -0400] "GET / HTTP/1.1" 200 +10801 111.111.111.111 - - [08/Oct/2007:11:17:55 -0400] "GET /style.css HTTP/ +1.1" 200 3225 123.123.123.123 - - [26/Apr/2000:00:23:48 -0400] "GET /pics/wpaper.gif + HTTP/1.0" 200 6248 123.123.123.123 - - [26/Apr/2000:00:23:40 -0400] "GET /asctortf/ HTTP/ +1.0" 200 8130 123.123.123.123 - - [26/Apr/2000:00:23:48 -0400] "GET /pics/5star2000. +gif HTTP/1.0" 200 4005 123.123.123.123 - - [26/Apr/2000:00:23:50 -0400] "GET /pics/5star.gif +HTTP/1.0" 200 1031 123.123.123.123 - - [26/Apr/2000:00:23:51 -0400] "GET /pics/a2hlogo.jp +g HTTP/1.0" 200 4282 123.123.123.123 - - [26/Apr/2000:00:23:51 -0400] "GET /cgi-bin/newcoun +t?jafsof3&width=4&font=digital&noshow HTTP/1.0" 200 36 172.16.130.42 - - [26/Apr/2000:00:00:12 -0400] "GET /contacts.html HTT +P/1.0" 200 4595 10.0.1.3 - - [26/Apr/2000:00:17:19 -0400] "GET /news/news.html HTTP/1. +0" 200 16716 129.21.109.81 - - [26/Apr/2000:00:16:12 -0400] "GET /download/windows/ +asctab31.zip HTTP/1.0" 200 1540096 192.168.198.92 - - [22/Dec/2002:23:08:37 -0400] "GET / HTTP/1.1" 200 6 +394 192.168.198.92 - - [22/Dec/2002:23:08:38 -0400] "GET /images/logo.gif +HTTP/1.1" 200 807 192.168.72.177 - - [22/Dec/2002:23:32:14 -0400] "GET /news/sports.html + HTTP/1.1" 200 3500 192.168.72.177 - - [22/Dec/2002:23:32:14 -0400] "GET /favicon.ico HTTP +/1.1" 404 1997 192.168.72.177 - - [04/Nov/2012:23:32:15 -0400] "GET /style.css HTTP/1 +.1" 200 4138 192.168.72.177 - - [22/Dec/2002:23:32:16 -0400] "GET /js/ads.js HTTP/1 +.1" 200 10229 192.168.72.177 - - [22/Dec/2002:23:32:19 -0400] "GET /search.php HTTP/ +1.1" 400 1997 127.0.0.1 - - [10/Apr/2007:10:39:11 +0300] "GET / HTTP/1.1" 500 606 127.0.0.1 - - [10/Apr/2007:10:39:11 +0300] "GET /favicon.ico HTTP/1.1" + 200 766 139.12.0.2 - - [10/Apr/2007:10:40:54 +0300] "GET / HTTP/1.1" 500 612 139.12.0.2 - - [10/Apr/2007:10:40:54 +0300] "GET /favicon.ico HTTP/1.1 +" 200 766 127.0.0.1 - - [10/Apr/2007:10:53:10 +0300] "GET / HTTP/1.1" 500 612 127.0.0.1 - - [10/Apr/2007:10:54:08 +0300] "GET / HTTP/1.0" 200 3700 127.0.0.1 - - [10/Apr/2007:10:54:08 +0300] "GET /style.css HTTP/1.1" 2 +00 614 127.0.0.1 - - [10/Apr/2007:10:54:08 +0300] "GET /img/pti-round.jpg HTT +P/1.1" 200 17524 127.0.0.1 - - [10/Apr/2007:10:54:21 +0300] "GET /unix_sysadmin.html HT +TP/1.1" 200 3880 217.0.22.3 - - [04/Nov/2012:10:54:51 +0300] "GET / HTTP/1.1" 200 34 217.0.22.3 - - [10/Apr/2007:10:54:51 +0300] "GET /favicon.ico HTTP/1.1 +" 200 11514 217.0.22.3 - - [10/Apr/2007:10:54:53 +0300] "GET /cgi/pti.pl HTTP/1.1" + 500 617 127.0.0.1 - - [10/Apr/2007:10:54:08 +0300] "GET / HTTP/0.9" 200 3700 217.0.22.3 - - [10/Apr/2007:10:58:27 +0300] "GET / HTTP/1.1" 200 3700 217.0.22.3 - - [10/Apr/2007:10:58:34 +0300] "GET /unix_sysadmin.html H +TTP/1.1" 200 3880 217.0.22.3 - - [10/Apr/2007:10:58:45 +0300] "GET /talks/Fundamentals/r +ead-excel-file.html HTTP/1.1" 404 31

Output:

66.249.65.107 - - [11/Nov/2012:19:33:01 -0400] "GET /support.html HTTP +/1.1" 200 11179 111.111.111.111 - - [11/Nov/2012:19:33:01 -0400] "GET / HTTP/1.1" 200 +10801

The join:

my $mergedYesterday = join '/', ( split ' ', $yesterday )[ 2, 1, 4 ]; ^ ^ ^ ^ ^ ^ | | | | | | | | | | | + - 2 +012 | | | | + - Nov | | | + - 11 | | + - Sun Nov 11 19:31 +:46 2012 | + - Use same delimiter as in log records + - 11/Nov/2012

The capturing regex

/\[([^:]+)/; ^ ^ | | | + - Capture everything up to the first colon, e.g., 11/Nov/2012 + - Anchor at left bracket

In reply to Re: counting yesterdays hits in a logfile by Kenosis
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.