+ -
当前位置:首页 → 问答吧 → how to deal with this compilation error ?

how to deal with this compilation error ?

时间:2010-11-10

来源:互联网

cat test5
use DBI;
use strict;


$dbh = DBI->connect("DBI:mysql:database=somedb:host=localhost","user",
                        "pass",{'RaiseErr' => 1, 'AutoCommit' => 0});
$sth = $dbh->prepare("INSERT INTO users(fname,lname)         VALUES(?,?)" );
$sth->execute("li","mary");
$sth->execute("ma","tuanwei");
$dbh->disconnect;




perl test5
Global symbol "$dbh" requires explicit package name at test5 line 5.
Global symbol "$sth" requires explicit package name at test5 line 7.
Global symbol "$dbh" requires explicit package name at test5 line 7.
Global symbol "$sth" requires explicit package name at test5 line 8.
Global symbol "$sth" requires explicit package name at test5 line 9.
Global symbol "$dbh" requires explicit package name at test5 line 10.
Execution of test5 aborted due to compilation errors.



请教各位怎样解决

作者: limary5   发布时间: 2010-11-10

use strict; 注释掉该行

或给变量作用域指示,如my $dbh = ***

作者: iamlimeng   发布时间: 2010-11-10

谢谢

作者: limary5   发布时间: 2010-11-10

楼主你这段程序是 Perl 代码,
你得学一下 Perl 才能维护它。

学习 Perl 建议从小骆驼开始。

作者: flw   发布时间: 2010-11-10