my @birds = @{ $self->{farmBirds} };
####
package Farm;
use strict;
use warnings;
sub new {
my $className = shift;
my $self = {
farmBirds => [], # initialisation not strictly required,
# but good for documentation purposes...
# ...
};
bless $self, $className;
return $self;
}
sub addFarmBirds {
my $self = shift;
push @{ $self->{farmBirds} }, @_;
}
sub getFarmBirds {
my $self = shift;
return @{ $self->{farmBirds} };
}
1;
####
#!/usr/bin/perl
use strict;
use warnings;
use Farm;
my $farm = Farm->new();
$farm->addFarmBirds( qw(X Y Z) );
my @birds = $farm->getFarmBirds();
print "@birds\n";