I have a fragment in this form:
my $a = $some_href->{$code}{'A'}; # a number or undef
my $b = $some_href->{$code}{'B'}; # a number or undef
$a = 0 unless defined($a);
$b = 0 unless defined($b);
my $total = $a + $b;
The reality is even more messy, since more than two variables are concerned.
What I really want to write is this:
my $total = $some_href->{$code}{'A'} + $some_href->{$code}{'B'};
and have undef correctly evaluate to 0 but I get these warnings in almost every run:
Use of uninitialized value in addition (+) at Stats.pm line 192.
What's the best way to make these messages go away?
NB: I 'use strict' and 'use warnings' if that s relevant.