Cleaning up some old code on server ... getting an error on line 228 ... pulling out snippet ... the while ($i < $num_cols) is the line with the error AH01215 "Use of uninitialized value $num_cols in numeric lt(<) at"
I added in the my and attempted checking for not defined, the code works, but I would like to get the code working without web server error log messages.
I have several of these "Use of uninitialized" errors, hoping seeing how to fix this will help me with the rest.
$sth = $h->prepare($sel);
if ($sth == 0) {
print "<XMLRSSQLERROR>ERROR: $DBI::errstr</XMLRSSQLERROR>\n";
exit;
}
if (!$sth->execute) {
print "<XMLRSSQLERROR>ERROR: $DBI::errstr</XMLRSSQLERROR>\n";
exit;
}
my $num_cols = $sth->{NUM_OF_FIELDS};
#Start the XML output
#Start the RS section and add the table name
print "<RS>\n";
print "$table\n";
#Start the SCHEMA section
print "<SCHEMA>\n";
my @columns = @{$sth->{NAME}};
my @type = @{$sth->{TYPE}};
my $i = 0;
while ($i < $num_cols) {
print "<$columns[$i]>";
if (($type[$i] == 1) or ($type[$i] == 12) or ($type[$i] == -1)) {
print "char";
} elsif (($type[$i] == 4) or ($type[$i] == 5) or ($type[$i] == -6)) {
print "int";
} elsif (($type[$i] == 2) or ($type[$i] == 6) or ($type[$i] == 7) or ($type[$i] == 8)) {
print "float";
} elsif (($type[$i] == 11) or ($type[$i] == 10) or ($type[$i] == 9)) {
print "datetime";
} else {
print "$type[$i]"
}
print "</$columns[$i]>\n";
$i += 1;
}
#End the SCHEMA section
print "</SCHEMA>\n";
int? The undefined value? Simply casting something when you don't even know what the problem is, is not the proper approach to take. An undefined value in Perl when cast to an int will result in a value of0.