我在调用带有哈希的构造函数时遇到了一些问题。我得到错误:
“Sumcheck.pm 第 4 行哈希分配中的奇数个元素”。Sumcheck.pm 看起来像这样:
package Sumcheck;
sub new {
my ($debug, $debug_matches,%checkHash) = @_;
my $self = {};
$self->{DEBUG} = $debug;
$self->{DEBUG_MATCHES} = $debug_matches;
$self->{CHECKRESULT_OK} = "COMPLIANT";
$self->{CHECKRESULT_ERROR} = "NONCOMPLIANT";
$self->{checkHash} = %checkHash;
#print %checkHash;
bless($self);
return $self;
}
1;
我这样称呼它(只是一个随机哈希):
use Sumcheck;
$debug = 0;
$debug_matches = 1;
%checkHash = ( 'The Shining' => 'Kubrick',
'Ten Commandments' => 'DeMille',
'Goonies' => 'Donner',);
$sumCheck = Sumcheck->new($debug, $debug_matches, %checkHash);
为什么我会收到此错误?它是如何解决的?
谢谢 :)