#! perl -slw use strict; use Date::Manip; use Data::Dumper; my $now = ParseDate( scalar localtime()); my $then = DateCalc( $now, ParseDateDelta( "7 hours 48 minutes ago" )); my $err; my $re = qr/ ^.*? # Skip the first part \[([^\]]+)\]\s+ # capture everything between [] "[^"]+"\s+ # skip a quoted string and whitespace .*? # and a couple of numbers or blanks "( [^"]+ )" # capture the next quoted string /x; my %referrers; while() { my @chunks = /$re/; my $ts = ParseDate $chunks[0]; print "The line '@chunks' was logged ", Delta_Format( DateCalc( $ts, $now, \$err ), 2, ("%mt")), " minutes ago."; if ( Date_Cmp( $ts, $then ) > 0 and Date_Cmp( $ts, $now ) < 0 ) { print "The previous line is within the window. Counting..."; $referrers{$chunks[1]}++; } else { print "Discarding previous line"; } } print "\nThese are the referrers counted:\n", Dumper(\%referrers); __DATA__ 24.208.200.247 - - [10/Dec/2002:18:05:09 -0500] "GET /images/header_aod2_08.gif HTTP/1.0" 200 663 "http://www.indystar.com/help/help/available.html" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; H010818)" 24.208.200.247 - - [10/Dec/2002:18:08:13 -0500] "GET /images/header_aod2_10.gif HTTP/1.0" 304 - "http://www.indystar.com/help/help/available.html" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; H010818)" 24.208.200.247 - - [10/Dec/2002:18:11:19 -0500] "GET /images/storysearch2.gif HTTP/1.0" 200 142 "http://www.indystar.com/help/help/available.html" "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; H010818)"