Chad Your program is throwing the error only because you have warnings enabled. The solution is:
$hits{$hour} += 1; But I'd be interested to know why you had to use '+ 1'? Also, I think my $hour = ( split /:/, $line )[1]; is nicer. HTH Rob ----- Original Message ----- From: "chad kellerman" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, October 15, 2002 4:58 PM Subject: counter for hash > 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 > > > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]