Hello,

    I wrote a script that goes thru the a access logs of a web server
and prints out the hour and number of hits/hour.  THe only problem is
that if i use warnings I get a bunch of errors when I count the hits.

Use of uninitialized value in addition (+) at scripts/hits.pl line 14,
<IN> line 20569.


#!/usr/bin/perl

use warnings;
use strict;

#define variables
my %hits;

open IN, '<', $ARGV[0] or die "cannot open log file: $!";

while (my $line = <IN>) {
     chomp $line;
     my (undef, $hour,undef) = split(/:/, $line);
     $hits{$hour} = $hits{$hour}+1;
}

foreach my $hour (sort keys %hits) { 
     print "$hour \+ -\+".$hits{$hour},"\n";
}


The problem lies in the line that says:

$hits{$hour} = $hits{$hour}+1;

What it the best way to create a counter?

  I have seen $var++, it would not work here I had to use +1.

Thanks for the info,

chad




Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to