#!/usr/local/bin/perl -w
use strict;
use warnings;
use DateTime::Format::Strptime;
my $Strp = new DateTime::Format::Strptime(pattern => '%Y-%b-%d %T',);
my $infile = 'logfile-2008-01-11.log';
my $outfile = 'report-2008-01-11.txt';
my($fh_out, $fh);
my %lookup;
my $channel = 'two';
my $time_delta = 3600; # seconds = 1 hour
open($fh_out, '>', $outfile) or die "Could not open outfile: $!";
open($fh, '<', $infile) or die "Could not open logfile: $!";
while (<$fh>) {
next unless /$channel/;
# $_ =~ m/^(.*) UTC.*refs = (\d+)$/;
# my $dt = $Strp->parse_datetime("$1");
# my $timestamp = $dt ->epoch();
# my $refs = "$2";
my ($dt, $timestamp, $refs);
if ( m/^(.*) UTC.*refs = (\d+)$/ ){
# right here, just after the match, is the only
# place it's safe to use $1 and $2 - tuck them away:
my $t = $1;
$refs = $2;
$dt = $Strp->parse_datetime($t);
$timestamp = $dt ->epoch();
}
else {
warn "No match: $_ \n";
next;
}
if ( defined($lookup{$refs}) && $lookup{$refs} + $time_delta <= $timestamp ) {
print $fh_out "REFS $refs: occurrences at " . $lookup{$refs} . "and $timestamp \n";
print "REFS $refs: occurrences at " . $lookup{$refs} . " and $timestamp \n";
}
$lookup{$refs} = $timestamp;
}
close $fh_out;
#close $fh;
####
2007-Jan-11 00:00:00 UTC (GMT +0000) - Poll: channel = one, ref = com, id = 595143009
2007-Jan-07 00:00:01 UTC (GMT +0000) - Poll: channel = two, ref = com, id = 133714761
2007-Jan-11 00:00:01 UTC (GMT +0000) - Poll: channel = one, ref = com, id = 595131400
2007-Jan-11 00:00:02 UTC (GMT +0000) - Poll: channel = two, ref = com, id = 660868931
2007-Jan-11 00:00:02 UTC (GMT +0000) - Poll: channel = two, ref = com, id = 595191883
2007-Jan-11 00:00:03 UTC (GMT +0000) - Poll: channel = one, ref = com, id = 098533326
2007-Jan-11 00:00:03 UTC (GMT +0000) - Poll: channel = three, ref = com, id = 659718092
2007-Jan-11 00:00:04 UTC (GMT +0000) - Poll: channel = three, ref = com, id = 006456768
2007-Jan-11 00:00:05 UTC (GMT +0000) - Poll: channel = one, ref = com, id = 133714761
####
2007-Jan-11 00:00:05 UTC (GMT +0000) - Poll: channel = one, ref = com, id = 133714761 1