I'm creating a new object like this:
TestObject->new(@array1, @array2)
My new
method looks like this:
sub new {
my $class = shift;
my $self = {};
my $self->{Array1} = shift;
my $self->{Array2} = shift;
bless($self, $class);
return $self;
}
As a simple test to access the data, I'm trying this, and then once I get it working, I can build more meaningful logic:
sub mymethod {
my $self = shift;
my $param = shift;
my $array1Value = shift(my $self->{Array1});
my $array2Value = shift(my $self->{Array2});
print $array1Value." ".$array2Value;
}
But when I call mymethod
, I get this error:
Type of arg 1 to shift must be array (not hash element) at Tests/MyObject.pm line 21, near "})"
Suggestions? I read this page on Perl data structures, but they don't have examples for creating a hash of arrays using arguments to a method using shift
. So my problem might be there.