Chad Kellerman wrote:
>
> Hello,
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 addi
japhy,
you are correct. That it what I wanted to convey. But with
everyone's input I understand what I was missing.
thanks again,
chad
On Tue, 2002-10-15 at 12:59, Jeff 'japhy' Pinyan wrote:
> On Oct 15, Rob said:
>
> >From: "chad kellerman" <[EMAIL PROTECTED]>
> >
> >> $hits{$ho
On Oct 15, Rob said:
>From: "chad kellerman" <[EMAIL PROTECTED]>
>
>> $hits{$hour} = $hits{$hour}+1;
[snip]
>> $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.
>
>But I'd be interested to know w
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: "ch
Chad Kellerman wrote:
> Use of uninitialized value in addition (+) at scripts/hits.pl line 14,
> line 20569.
> ...
> 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 h
$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:[E