How can I add a field with an array value to my Perl object?
- by superstar
What's the difference between these two constructors in perl?
1) sub new {
my $class = shift;
my $self = {};
$self->{firstName} = undef;
$self->{lastName} = undef;
$self->{PEERS} = [];
bless ($self, $class);
return $self;
}
2) sub new {
my $class = shift;
my $self = {
_firstName => shift,
_lastName => shift,
_ssn => shift,
};
bless $self, $class;
return $self;
}
I am using the second one so far, but I need to implement the PEERS array in the second one? How do I do it with the second constructor and how can we use get and set methods on those array variables?