buz260 has asked for the wisdom of the Perl Monks concerning the following question:
However the above can only get / set / store scalars. To have object properties which can store arrays, I have been doing the following:sub entity2 { $_[0]->{entity2}=$_[1] if defined $_[1]; $_[0]->{entity2 +} } sub IxnCount { $_[0]->{IxnCount}=$_[1] if defined $_[1]; $_[0]->{IxnCo +unt} }
To set the property, it's $object->synsatMaxScore1(@array). However it seems that the data can ultimately only be stored as a reference to an array, and also when getting the property, at the moment you then have to derefererence the array:sub synsatMaxScore1 { my ($self, @pmIDs) = @_; if (@pmIDs) { my $ref = \@pmIDs; $self->{synsatMaxScore1} = $ref; } return $self->{synsatMaxScore1}; }
Is there any way of changing the method so that it can return arrays too? I guess this is something to do with the way Perl internally handles Object Oriented modules... Thanks in advance.my $arrayref = $object->synsatMaxScore1; my @array = @$arrayref;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bean properties...
by Anonymous Monk on Apr 28, 2009 at 10:00 UTC | |
by buz260 (Novice) on Apr 28, 2009 at 14:58 UTC | |
by Anonymous Monk on Apr 28, 2009 at 15:21 UTC | |
by buz260 (Novice) on Apr 30, 2009 at 08:03 UTC |