我试图在perl中创建一个对象,该对象包含一个数组和两个整数标量。
到目前为止,我有:
new
{
$class = shift;
$self = [];
$int1 = shift;
$int2 = shift;
bless($self, $class);
}
这适用于使用$ self-> [number]访问数组
我希望能够访问int1和int2。如果将它们放在构造函数之外,则当我更改它们时,它们将针对对象的每个实例而更改。
谢谢。
sub new {
my ($class, $int1, $int2) = @_;
my $self = bless({}, $class);
$self->{array} = [];
$self->{int1} = $int1;
$self->{int2} = $int2;
return $self;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句