Reputation: 13
I've this error:
Use of uninitialized value in concatenation (.) or string at...
$queryH= $dbh->prepare($query);
$queryH->execute();
my $i=0;
my $result;
while (@data = $queryH->fetchrow_array())
{
$result=$data[$i];
if ($result)
{
print "$result \n";
}
else
{
print "Records Not Found!\n";
last;
}
print "\n";
$i++;
}
print "\n\n";
$queryH->finish();
$dbh->disconnect();
What error is there in my code?
The error is on the line:
$result=$data[$i];
Upvotes: 0
Views: 2247
Reputation: 54381
You are starting out with $i=0
and you increment it with each pass of the while
loop. You look at $data[$i]
once for each line of database result. So for the first row, you look at $data[0]
. For the second row of data, you look at $data[1]
and so on. At some point, your $i
(which is effectively a rowcount starting at zero) will be higher than the number of fields per row. That produces the error message.
If you put in a print "$i\n"
in the beginning of the while
block you will see what I am talking about.
Upvotes: 1