我想在類構造函數中創建調度表。執行失敗,出現下面提到的錯誤。在perl裏面的類構造函數中創建調度表
錯誤: 在../lib/Parser.pm的子例程條目中使用未初始化的值。 當在../lib/Parser.pm處使用「strict refs」時,不能使用字符串(「」)作爲子程序ref。
代碼:
package parser;
use strict;
use warning;
@packet = ("join","release","status");
#constructor
sub new {
my ($class) = shift;
my $self = {
_callerMDN => shift,
_calleeList => shift,
_serverIp => shift,
_packetHandler => {
join => \&joinHandler, #Dispatch table,variable "join" stores func reference
release => \&releaseHandler, #variable "release" stores func reference
status => \&statusHandler #variable "stores" stores func reference
},
_mdnHandler => {},
};
print ("The Server IP = $self->{_serverIp}\n") if ($debug);
print ("CallerMDN = $self->{_callerMDN}\n") if ($debug);
print ("TcpDump File Name = $self->{_tcpdumpFile}\n") if ($debug);
bless($self, $class);
return $self;
}
sub start {
my ($self,$data) = @_;
if ($data ~= "Incoming Packet") {
$self->{_packetHandler}->{$packet[0]}->($data);#**Error while calling "joinHandler" function**
}
elsif ($data ~= "Outgoing Packet"){
$self->{_packetHandler}->{$packet[1]}->($data);#**Error while calling "releaseHandler" function**
}
else {
$self->{_packetHandler}->{$packet[2]}->($data);#**Error while calling "statusHandler" function**
}
}
sub joinHandler {
my ($self,$data) = @_;
#parse packet
print ("Incoming Packet parsed");
}
sub releaseHandler {
my ($self,$data) = @_;
#parse packet
print ("Outgoing packet parsed");
}
sub statusHandler {
my ($self,$data) = @_;
#parse packet
print ("status packet");
}
請幫我瞭解並解決問題。