0
我已經爲C#工具編寫了幾個perl包裝器模塊。這個想法是,腳本會傳遞一個設備名稱,端口號和用於建立通信套接字的服務器地址。當我寫一個腳本來使用這些模塊我得到一個編譯失敗的錯誤需要編譯Perl錯誤訪問對象屬性的錯誤
"Can't call method "_serveraddr" on an undefined value at Device.pm line 23.
Compilation failed in require at Launch.pl line 11.
BEGIN failed--compilation aborted at Launch.pl line 11."
Launch.pl
use Device;
use System;
my ($serverAddress, $port, $reportFile) = @_;
my $System = new System($serverAddress, $port);
my $dut = new Device('DEV',127.0.0.1,5000);
Device.pm
package Device;
use strict;
use warnings;
use Command;
use Comm;
sub new {
my $class = shift;
my $self = {
_device => shift,
_serveraddr => shift,
_port => shift
};
bless $self, $class;
return $self;
}
my $SockObj = Comm->new($self->_serveraddr, $self->_port);
my $ComObj = Comm->new();
sub Action1 {
my ($self, $x, $y) = @_;
my $tmp = {
'hash1' => 'Command',
'value1' => $x,
'value2' => $y,
'Device' => $self->{_device}
};
$InputRequest = $ComObj->CreateInputString($tmp);
$SockObj->WriteInfo($InputRequest);
my $Response = $SockObj->ReadData();
$ComObj->TapResponse($Response);
}
System.pm
package System;
use strict;
use warnings;
use Comm;
use Command;
my $SockObj = Comm->new();
my $ComObj = Command->new();
sub new {
my $class = shift;
my $self = {
_serveraddr => shift,
_port => shift
};
bless $self, $class;
return $self;
}
有人可以請help..I不知道如何移動forward..Please讓我知道如果這個問題不清楚..
我認爲問題是,在這條線
my $SockObj = Comm->new($self->_serveraddr, $self->_port);
$自包含未定義值。我如何解決?無論如何,我是perl的新手,我不知道我們是否可以使用散列來訪問對象的屬性。
此外,在'Launch.pl'中,127.0.0.1不是您認爲的那樣。 – Grrrr 2011-04-06 13:04:14