W
Walter Roberson
I am trying to figure out the logical error in the following code snippit.
Assume, please, that the code is 'use strict' and 'use warnings' clean.
Also assume, please, that $nhit_href is a valid hash reference, and that
it would be relatively common for $nhit_href->{$key} to not already
exist.
my $newcount = 1;
$newcount = $nhit_href->{$key} + 1
if exists $nhit_href->{$key} && defined $nhit_href->{$key};
The problem: from time to time (but not at all often), I get the message:
Use of uninitialized value in addition (+) at /usr/people/roberson/src/CacheUtils.pm line 242.
where line 242 is the second statement.
Have I perhaps missed something in operator precidences? Under what
circumstances might I be trying to increment an uninitialized
$nhit_href->{$key} considering that I -thought- the code is checking for
existance and definedness before attempting the increment?
Assume, please, that the code is 'use strict' and 'use warnings' clean.
Also assume, please, that $nhit_href is a valid hash reference, and that
it would be relatively common for $nhit_href->{$key} to not already
exist.
my $newcount = 1;
$newcount = $nhit_href->{$key} + 1
if exists $nhit_href->{$key} && defined $nhit_href->{$key};
The problem: from time to time (but not at all often), I get the message:
Use of uninitialized value in addition (+) at /usr/people/roberson/src/CacheUtils.pm line 242.
where line 242 is the second statement.
Have I perhaps missed something in operator precidences? Under what
circumstances might I be trying to increment an uninitialized
$nhit_href->{$key} considering that I -thought- the code is checking for
existance and definedness before attempting the increment?