buz260 has asked for the wisdom of the Perl Monks concerning the following question:

First of all, I'm not sure what Perl's equivalent of Java's bean properties are called (any ideas?). I am using methods of a certain class to store data - eg
sub entity2 { $_[0]->{entity2}=$_[1] if defined $_[1]; $_[0]->{entity2 +} } sub IxnCount { $_[0]->{IxnCount}=$_[1] if defined $_[1]; $_[0]->{IxnCo +unt} }
However the above can only get / set / store scalars. To have object properties which can store arrays, I have been doing the following:
sub synsatMaxScore1 { my ($self, @pmIDs) = @_; if (@pmIDs) { my $ref = \@pmIDs; $self->{synsatMaxScore1} = $ref; } return $self->{synsatMaxScore1}; }
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:
my $arrayref = $object->synsatMaxScore1; my @array = @$arrayref;
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.

Replies are listed 'Best First'.
Re: Bean properties...
by Anonymous Monk on Apr 28, 2009 at 10:00 UTC
    #!/usr/bin/perl -- use strict; use warnings; beans(); warn $_ for beans(); # 7 warn scalar beans(); sub beans { return unless defined wantarray; warn 'beans'; my @beans = 1 .. 3; return wantarray ? @beans : \@beans; } __END__ beans at - line 12. 1 at - line 7. 2 at - line 7. 3 at - line 7. beans at - line 12. ARRAY(0x183aaa0) at - line 8.
      Sorry, can you explain that please?