I'm getting an error in Perl and I can't work out why.
Error: Not an ARRAY reference at Service.pm, line 20
my $array = [ { name => 'George', surname => 'Marley' } ];
my $helper = CustMessage->new();
$helper = CustMessage->getMessage($array);
then in my utility file I have:
sub getMessage {
my ($self, $args) = @_;
my $stringsArray = shift;
my $strings = Service->new({
serviceId => $self->_serviceId(),
});
return unless $strings;
$strings->getStrings($stringsArray);
}
and then in the Service method is:
sub getStrings {
my ($stringsArray, $self) = shift;
my @keys = map({ $_->{'name'} } @{$stringsArray});
my $key = join('', @keys);
$key = MIME::Base64::encode($key);
my %results;
$results{$key} = $self->_callStrings->($stringsArray);
$results{$key}->initialize();
$results{$key} = $self->{serviceCalls}->{getStrings};
return $self->{serviceCalls}->{getStrings};
}
The error is on line 2 of the getStrings method in Service.pm:
my @keys = map({ $_->{'name'} } @{$stringsArray});
,inmy ($stringsArray $self) = shift;?$helperan object first and then reassigned the value of the output ofgetMessage? I'm more used to seeing things like:my $helper = CustMessage->new(); my $msg = $helper->getMessage($array);. I guess if you don't use$helperagain as an object then the reassignment works? Is this a typical pattern?