Uninitialized Value in String 'eq' Perl
I think you are looking for the error in the wrong place. For a warning triggered inside an if-elsif-else
statement or other complex block of code, older versions of Perl may identify the warning as occuring on the first line of the statement.
------ warn.pl ------
my $x = 0;
my $y;
if ($x == 1) { # line 3
} elsif ($x == 2) {
} elsif ($x == 3) {
} elsif ($y == 4) { # line 7
}
$ perl5.14.2 -w warn.pl
Use of uninitialized value $y in numeric eq (==) at warn.pl line 7.
$ perl5.8.6 -w warn.pl
Use of uninitialized value in numeric eq (==) at line 3.
You might check to see if $pieces[0]
is defined before you do comparisons. Most of the time this will prevent the warning:
my @pieces = split(/=/, $var);
my $label = defined($pieces[0]) ? $pieces[0] : ""; #if not defined init to ""
my $value = defined($pieces[1]) ? $pieces[1] : "";
if($label eq "PromotionNumber") {
$promoNumber = $value;
} elsif ($label eq "Type") {
#More similar code follows