Andy,

Here is how I would do it.

- convert all times to seconds.
- make all times relative to the base time.
- determine a major key, the fifteen minute interval it's in relative to the base time.
- determine a minor key, the one minute interval it's in relative to the major key.
- save memory by processing each 15 minute interval as it completes, in the while loop.

Hope this gets you on track.

YuckFoo

#!/usr/bin/perl use strict; use DateTime; my $MAJOR_SIZE = 15 * 60; my $MINOR_NUM = 15; my $MINOR_SIZE = $MAJOR_SIZE / $MINOR_NUM; my $BASETIME = 0; my %ABBREVS; @ABBREVS{qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)} = (1.. +12); my ($bucket, $oldmajor); while (my $line = <DATA>) { chomp ($line); my (undef, $day, $mon, $year, $hour, $min, $sec) = split(/\W/, $li +ne); my $time = DateTime->new( year => $year, month => $ABBREVS{$mon}, day => $day, hour => $hour, minute => $min, second => $sec, ); $time = $time->epoch(); $BASETIME = $BASETIME || $time; my $relative = $time - $BASETIME; my $major = int($relative / $MAJOR_SIZE); my $minor = int(($relative - ($major * $MAJOR_SIZE)) / $MINOR_SIZE +); if ($major != $oldmajor) { if (defined($bucket)) { process($bucket); $bucket = undef; } } if (!defined($bucket)) { $bucket = {}; $bucket->{major} = $major; $bucket->{minors} = []; } $bucket->{minors}[$minor]++; $oldmajor = $major; print "$line $time $relative $major $minor\n"; } if (defined($bucket)) { process($bucket); } #----------------------------------------------------------- sub process { my ($bucket) = @_; my $major = ($bucket->{major} * $MAJOR_SIZE) + $BASETIME; print "\nmajor: $major\n"; for my $i (0..$MINOR_NUM-1) { my $minor = ($i * $MINOR_SIZE) + $major; print " minor: $minor $bucket->{minors}[$i]\n"; } print "\n"; } __DATA__ [15/Jun/2003:00:02:27 -0500] [15/Jun/2003:00:03:44 -0500] [15/Jun/2003:00:03:44 -0500] [15/Jun/2003:00:03:44 -0500] [15/Jun/2003:00:07:28 -0500] [15/Jun/2003:00:08:44 -0500] [15/Jun/2003:00:08:45 -0500] [15/Jun/2003:00:08:45 -0500] [15/Jun/2003:00:12:28 -0500] [15/Jun/2003:00:13:45 -0500] [15/Jun/2003:00:13:45 -0500] [15/Jun/2003:00:13:46 -0500] [15/Jun/2003:00:17:29 -0500] [15/Jun/2003:00:18:46 -0500] [15/Jun/2003:00:18:46 -0500] [15/Jun/2003:00:18:47 -0500] [15/Jun/2003:00:22:29 -0500] [15/Jun/2003:00:23:47 -0500] [15/Jun/2003:00:23:47 -0500] [15/Jun/2003:00:23:48 -0500] [15/Jun/2003:00:27:30 -0500] [15/Jun/2003:00:28:48 -0500] [15/Jun/2003:00:28:48 -0500] [15/Jun/2003:00:28:49 -0500] [15/Jun/2003:00:32:30 -0500] [15/Jun/2003:00:33:49 -0500] [15/Jun/2003:00:33:49 -0500] [15/Jun/2003:00:33:49 -0500] [15/Jun/2003:00:37:31 -0500]

In reply to Re: Parsing of the web log file, access_log by YuckFoo
in thread Parsing of the web log file, access_log by Andy61

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.