【发布时间】:2013-07-08 14:02:13
【问题描述】:
我有这个改变 MySQL 数据库数据的 perl 脚本,每次我运行它都会收到以下错误
Use of uninitialized value in addition (+) at ./cdr_db.pl-m line 88.
查看第 80 到 88 行的代码
### archive cdr records
$sth = $dbh2->prepare(
"SELECT max($tablename2_archive.EventID) from $tablename2_archive")
or die "Couldn't prepare statement: " . $dbh->errstr;
$sth->execute()
or die
"Database error trying to poll $tablename2_archive.EventID for archive use: "
. $sth->errstr . "\n";
my $nextEventID = $sth->fetchrow_array + 1;
这是完整的脚本
我只是不明白错误是什么。
【问题讨论】:
-
看起来
$sth->fetchrow_array是undef。使用Data::Dumper仔细查看$sth和$sth->fetchrow_array。尝试printing out 查询(变量填写后),看看有没有问题。 -
另外,您应该知道,由于
$sth->fetchrow_array是一个数组,当您向其添加 1 时,您是在标量上下文中调用它... -
@JackManey:尽管它的标识符
fetchrow_array返回一个列表,它是来自数组的very different thing。 -
@Borodin - [检查文档] 是的。抱歉,我通常使用
fetchrow_arrayref或fetch绑定参数。
标签: perl