You may be better off using a hash for your code:
#!/usr/local/bin/perl -w use strict; my $processed_log = $ARGV[ 0 ]; # Now that we have the logs, let's give a breakdown of BIND/UNBINDS # per hour. To start, I'll make it easy and just do them on an hourly # basis (eg. 09:00-09:59, 10:00-10:59, etc...) open PROCESSED_LOG, '<', $processed_log or die "Cannot open $processed +_log: $!\n"; print"BINDS UNBINDS\n"; my %data; while ( <PROCESSED_LOG> ) { if ( /(\d\d):\d\d:\d\d.+?(UNBIND|BIND)/ ) { $data{ $1 }{ $2 }++; } } for my $hour ( sort keys %data ) { printf "Hour %s has %5d BINDS and %5d UNBINDS TOTAL=%-6d\n", $hou +r, @{ $data{ $hour } }{ qw/BIND UNBIND/ }, $data{ $hour }{ BIND } + $ +data{ $hour }{ UNBIND }; }
If you wanted to do it in five minute intervals then:
#!/usr/local/bin/perl -w use strict; my $processed_log = $ARGV[ 0 ]; my $minute_interval = 5; # or use command line or getopts() # Now that we have the logs, let's give a breakdown of BIND/UNBINDS # per hour. To start, I'll make it easy and just do them on an hourly # basis (eg. 09:00-09:59, 10:00-10:59, etc...) open PROCESSED_LOG, '<', $processed_log or die "Cannot open $processed +_log: $!\n"; print"BINDS UNBINDS\n"; my %data; while ( <PROCESSED_LOG> ) { if ( /(\d\d):(\d\d):\d\d.+?(UNBIND|BIND)/ ) { my $time = sprintf '%02d:%02d', $1, int( $2 / $minute_interval + ) * $minute_interval; $data{ $time }{ $3 }++; } } for my $hour ( sort keys %data ) { printf "Hour %s has %5d BINDS and %5d UNBINDS TOTAL=%-6d\n", $hou +r, @{ $data{ $hour } }{ qw/BIND UNBIND/ }, $data{ $hour }{ BIND } + $ +data{ $hour }{ UNBIND }; }

In reply to Re: Parsing LDAP log file given a time period by jwkrahn
in thread Parsing LDAP log file given a time period by spartan

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.