【问题标题】:Use of uninitialized value in concatenation (.) or string at在连接 (.) 或字符串中使用未初始化的值
【发布时间】:2014-01-08 20:00:53
【问题描述】:

我有这个错误:

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();

我的代码有什么错误?

错误就行了:

$result=$data[$i];

【问题讨论】:

  • 对不起...错误在这一行:$result=$data[$i];非常感谢:D
  • 您可能会发现this answer 很有用。
  • 好!!!非常感谢:D
  • 你想要完成什么?
  • 或者更具体地说,你想通过增加$i来实现什么?

标签: sql perl


【解决方案1】:

您从$i=0 开始,并随着while 循环的每次传递而递增它。对于数据库结果的每一行,您查看$data[$i] 一次。所以对于第一行,你看$data[0]。对于第二行数据,您查看$data[1] 等等。在某些时候,您的$i(实际上是从零开始的行数)将高于每行的字段数。这会产生错误消息。

如果您在while 块的开头输入print "$i\n",您就会明白我在说什么。

【讨论】:

    猜你喜欢
    • 2014-05-20
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-27
    • 2022-11-04
    相关资源
    最近更新 更多