【发布时间】:2011-11-25 22:19:42
【问题描述】:
我编写 perl 类,但我不知道如何在我的 $this 变量中包含数组或哈希?
我有一个pack.pm:
#!/usr/bin/perl -w
use strict;
use Parallel::ForkManager;
package Pack;
our $cgi = new CGI;
sub new {
my ($classe, $nom, $nbports, $gio) = @_;
my $this = {
"nom" => $nom,
"nbports" => $nbports,
"gio" => $gio
};
bless($this, $classe);
return $this;
}
...
1;
我想要一个@tab,我可以通过$this->tab 访问,但我不想将它以arg 形式提供给实例。
它在 Perl 中是如何工作的?
谢谢。
【问题讨论】:
-
你想做什么?你想要一个@tab,它是$this 的一部分,但你没有传递给new()?是否希望将其创建为空表,以便以后用作 $this->tab?
-
@AAT :是的,我想要 $this 的 @tab 部分,并且我不传递给 new(),一个空数组,在实例化时创建。我可以通过 $this->tab 访问。谢谢
标签: perl variables constructor instance