How can I add a field with an array value to my Perl object?
Posted
by superstar
on Stack Overflow
See other posts from Stack Overflow
or by superstar
Published on 2010-04-01T18:17:52Z
Indexed on
2010/04/01
19:43 UTC
Read the original article
Hit count: 257
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?
© Stack Overflow or respective owner