尝试用OOP编写一个perl模块,但是它可以将一个对象添加到一个数组中,当我使用Dump方法时,它会输出这样的错误数据。我的错误在哪里?
谢谢
bless( {
'_name' => 'CUSIP',
'_validation_array' => [],
'_seq' => '1'
}, 'Field' );
源代码:
package Field;
sub new {
my $class = shift;
my $self = {
_name => shift,
_seq => shift,
_validation_array => [ @_ ],
};
bless($self, $class);
return $self;
};
sub pushValidation(){
my $validation = shift;
push(@{$self->{_validation_array}}, $validation);
};
sub dump(){
foreach my $validation (@{$self->{_validation_array} }) {
#print Dumper($validation);#will work,
print $validation->{name}; #error, Use of uninitialized value
}
}
1;
这就是我调用此方法的方式:
my $validationObj = new Validation($validation->{name}, $validation->{seq});
$field->pushValidation($validationObj);