По мотивам http://stackoverflow.com/questions/2561451/how-do-i-use-an-a...
сделал свой вариант. Критика приветствуется.Сам класс, файл "ListContaine.pm"
#!/usr/bin/perluse strict;
use warnings;
package ListContainer;
sub new {
my $class = shift;
my $self = {
sftVersion => shift,
softwareSynonyms => [@_],
};
bless $self, $class;
return $self;
}
sub setSynonyms {
my ( $self, @newSoftwareSynonyms ) = @_;
$self->{softwareSynonyms} = \@newSoftwareSynonyms;
}
sub addSynonym {
my ( $self, $newSoftwareSynonym ) = @_;
push($self->{softwareSynonyms}, $newSoftwareSynonym);
}
sub getSynonyms {
my( $self ) = @_;
return @{$self->{softwareSynonyms}} ;
}
1;
Пользоваться так - файл "launcher.pl":
#!/usr/bin/perluse strict;
use warnings;
use File::Basename;
use lib dirname(__FILE__);
use ListContainer;
my @namesToBeInsertedInPlace = (
"sft First",
"sft Second",
);
my $justPacket = new ListContainer("MajorName", "name Tenth", "name Eleventh", "name Twelfth");
$justPacket->setSynonyms(@namesToBeInsertedInPlace);
$justPacket->addSynonym("Yet Another One");
my @theArray = $justPacket->getSynonyms();
print "Second element is:" . $theArray[1] . "\n";
print "Have " . ($#theArray + 1) . " members in the list:\n" ;
foreach my $singleName (@theArray) {
print ":\t" . $singleName . "\n";
}