我正在尝试在类构造函数中创建调度表。执行失败并出现以下错误。
错误: 在 ../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");
}
请帮助我理解和解决问题。