Somewhat shorter than other suggestions (by using the Date::Time modules):
use strict; use DateTime::Format::Flexible; use DateTime::Duration; my $one_hour = DateTime::Duration->new(hours => 1); my %loglines; while (<DATA>) { next unless /TWO/; # only handle log-items with for channel TWO my ($time, $ref) = /(.*) UTC.*refs = (\d+)$/; my $dt = DateTime::Format::Flexible->build( $time ); if (defined $loglines{$ref}) { my $difference = $dt->subtract_datetime( $loglines{$ref}->[0] +); if (DateTime::Duration->compare( $difference, $one_hour) == 1 +) { # check if difference more than 1 hour print $loglines{$ref}->[1], $_, "------------------------- +\n"; delete $loglines{$ref}; # reset the item } } else { $loglines{$ref} = [$dt, $_]; # save the item } } __DATA__ 2008-Jan-06 00:00:01 UTC (GMT +0000) - Poll: channel = ONE, refs = 595 +166299 2007-Jan-06 00:00:01 UTC (GMT +0000) - Poll: channel = TWO, refs = 595 +159906 2007-Jan-06 00:00:01 UTC (GMT +0000) - Poll: channel = THREE, refs = 6 +59975924 2007-Jan-06 00:00:04 UTC (GMT +0000) - Poll: channel = ONE, refs = 595 +148941 2007-Jan-06 00:00:04 UTC (GMT +0000) - Poll: channel = TWO, refs = 595 +131400 2007-Jan-06 00:00:04 UTC (GMT +0000) - Poll: channel = THREE, refs = 6 +59975924 2007-Jan-06 00:00:04 UTC (GMT +0000) - Poll: channel = ONE, refs = 595 +159906 2007-Jan-06 01:00:05 UTC (GMT +0000) - Poll: channel = ONE, refs = 595 +166299 2007-Jan-06 01:00:06 UTC (GMT +0000) - Poll: channel = TWO, refs = 595 +131400 2007-Jan-06 01:00:06 UTC (GMT +0000) - Poll: channel = TWO, refs = 659 +975924 2007-Jan-06 01:00:07 UTC (GMT +0000) - Poll: channel = THREE, refs = 5 +95148941
And the result is:
2007-Jan-06 00:00:04 UTC (GMT +0000) - Poll: channel = TWO, refs = 595 +131400 2007-Jan-06 01:00:06 UTC (GMT +0000) - Poll: channel = TWO, refs = 595 +131400 -------------------------
As the specification is a bit vague, I have chosen to reset the check once I have found two matching items more than 1 hour apart. You will then need again two new entries in the log more than one hour apart to trigger it.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James


In reply to Re: comb a logfile for time diff and occourance by CountZero
in thread comb a logfile for time diff and occourance by tuakilan

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.