The fundamental issue with your code is the split command, which leaves $id with the wrong stuff. You're parsing the date okay. A slight modification of the split, to something like:

split / - | tids = /;
And your code should work fine. This modification of your original produces the kind of output you desire:

#!/usr/bin/perl use strict; use warnings; use Time::Local; my $debug = shift || 0; my $header = 0; my $outfile = 'output.2008-01-01.log'; my($fh_out, $fh); open($fh_out, '>', $outfile) or die "Could not open outfile: $!"; my %track; while (<DATA>){ my ($date,$ignoreIDLiteral,$id) = split / - | tids = /; if ( $debug ) { print "Date = $date\n"; print "Literal = $ignoreIDLiteral\n"; print "Id = $id\n"; } chomp $id; my $time = dateconv($date); my $prevtime = $track{$id}{TIME}; $track{$id}{TIME}=$time; $track{$id}{DATE}=$date; $track{$id}{COUNT}++; if ( $prevtime and ( $time - $prevtime > 3600 ) ) { unless ( $header ) { print "TIDS time Occurance\ +n"; print "====================================================\ +n"; $header = 1; } print "$id\t$date\t$track{$id}{COUNT}\n" } } sub dateconv{ my $d = shift; my %month = qw[jan 1 feb 2 mar 3 apr 4 may 5 jun 6 jul 7 aug 8 sep 9 oct 10 nov 11 dec 12]; my @p = $d=~/(\d+)-(\w+)-(\d+)\s(\d+):(\d+):(\d+)/; $p[1]=$month{ lc $p[1] } - 1; return timelocal(@p[5,4,3,2,1,0]); } close $fh_out; __DATA__ 2008-Jan-01 00:00:00 UTC (GMT +0000) - Toll: channel = seven, ref = xx +x.xxxxxx.xxx.xxxxx.xxxxxxx.xxxxxxxxxxxxxxxxxxxxx, tids = 123456789 2008-Jan-01 00:10:00 UTC (GMT +0000) - Toll: channel = six, ref = xxx. +xxxxxx.xxx.xxxxx.xxxxxxx.xxxxxxxxxxxxxxxxxxxxx, tids = 987654321 2008-Jan-01 00:20:00 UTC (GMT +0000) - Toll: channel = three, ref = xx +x.xxxxxx.xxx.xxxxx.xxxxxxx.xxxxxxxxxxxxxxxxxxxxx, tids = 223344221 2008-Jan-01 00:30:00 UTC (GMT +0000) - Toll: channel = four, ref = xxx +.xxxxxx.xxx.xxxxx.xxxxxxx.xxxxxxxxxxxxxxxxxxxxx, tids = 998829992 2008-Jan-01 00:40:00 UTC (GMT +0000) - Toll: channel = three, ref = xx +x.xxxxxx.xxx.xxxxx.xxxxxxx.xxxxxxxxxxxxxxxxxxxxx, tids = 938874724 2008-Jan-01 00:50:00 UTC (GMT +0000) - Toll: channel = two, ref = xxx. +xxxxxx.xxx.xxxxx.xxxxxxx.xxxxxxxxxxxxxxxxxxxxx, tids = 229928828 2008-Jan-01 01:00:00 UTC (GMT +0000) - Toll: channel = five, ref = xxx +.xxxxxx.xxx.xxxxx.xxxxxxx.xxxxxxxxxxxxxxxxxxxxx, tids = 998822992 2008-Jan-01 01:10:00 UTC (GMT +0000) - Toll: channel = seven, ref = xx +x.xxxxxx.xxx.xxxxx.xxxxxxx.xxxxxxxxxxxxxxxxxxxxx, tids = 123456789
Output is:

./read_tolls.pl TIDS time Occurance ==================================================== 123456789 2008-Jan-01 01:10:00 UTC (GMT +0000) 2

In reply to Re: Comparing Dates and Reoccurance - Part II by dwm042
in thread Comparing Dates and Reoccurance - Part II 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.