my $now = &GetDate;
my $myHeader = &ReadMessage;
my $mySoftwareVersions = param('mySoftwareVersions');
my $q = new CGI;print $q->header();
use CGI::Carp(fatalsToBrowser);
getAllSoftwareVersions();
sub getAllSoftwareVersions
{
my $user = "zxxx";
my $passwd = "xxxx";
# my $tableName = "config_table";
# my $connection = DBI->connect("DBI:mysql:MESCI:hamysql02.stl.mo.boeing.com:18080", $user, $passwd, { AutoCommit => 0, RaiseError => 1}) or die "Couldn't connect to Database: " . DBI->errstr;
print "Must be connected\n\n";
print "\n\n";
# Error here.
my @Rows = &getConfigTableRows($connection, $config_table, $mySoftwareVersions );
my $total = @Rows;
print "total is ";
print $total;
上面的代码死于:
Global symbol "$connection" requires explicit package name
编辑 这个问题与:
- https://stackoverflow.com/questions/682695/how-do-i-resolve
- https://stackoverflow.com/questions/681557/xml-cannot-be-displayed-error-from-perl-cgi-script-using-mysql
希望原始发帖人能够对此进行清理,使其更有意义,但这是我们目前所掌握的内容,因此我们可以尝试提供帮助。
最佳答案
尽管 Kent 的回答是超前思考,但错误只是告诉您您没有声明 $connection
作为词法(“my”)变量。因此,perl 将其解释为您必须引用全局包。
当你使用一个 undefined variable 时,Raw Perl 不会提示,它认为它是一个全局包。你似乎有 strict
在某个地方(一种标准和推荐的做法),它希望您在使用变量之前声明您的变量。如果您没有在当前包(或“命名空间”)中声明变量,它会假设您指的是在另一个包中声明的变量,因此它会要求您附加包名称,只是为了保持一切清晰和光明正大.
my $connection = "Rainbow";
或
our $connection = 'French';
以防万一你有错误的想法,如果你关闭严格,错误消息就会消失,你的问题不会。他们可能会转入地下。
{ no strict;
my @rows = getConfigTableRows( $nothing, @other_stuff );
}
Perl 不会提示 $nothing
什么都不是。而这个易于修复的错误可能会在其他地方导致更微妙的错误。另外想想如果你已经成功分配了 $connection
,只需要输入:
{ no strict;
my @rows = getConfigTableRows( $connecion, $config_table, $mySoftwareVersions );
}
Perl 给你一条关于 '$connecion'
的消息,希望你能看出这是一个拼写错误,并且放弃至少 30 分钟看不到它并想知道你的查询是否错误,或者任何。
关于perl - 为什么我的 Perl 脚本会提示 'Global symbol "$connection"requires explicit package name'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/682870/