$hits{$hour}++ is valid and would work as stated. The reason you are getting the working is using the $Hits{$Hour} on the right side of the equal sign. You can use ++ or -- or += or -= with scalars, hash or array values.
Wags ;) -----Original Message----- From: chad kellerman [mailto:[EMAIL PROTECTED]] Sent: Tuesday, October 15, 2002 08:58 To: [EMAIL PROTECTED] 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 ********************************************************** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. **************************************************************** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]