I need to create a multi-dimensional array which will be passed to a class.
Here is sample code where I can reference the array elements outside of the class, but once I create a class and pass the multi-dimensional array, I'm not able to reference it inside of the class.
Output:
My Array Value = 3
Can't use string ("1") as an ARRAY ref while "strict refs" in use at test.pl line 18.
package TestClass;
use strict;
sub new
{
my $class = shift;
my $self =
{
_array => shift
};
bless $self, $class;
return $self;
}
sub print
{
my ($self) = @_;
print "TestClass variable = " . @{$self->{_array}->[0]}[1] . "\n";
}
my @my_array = ();
push(@my_array, [1,2]);
push(@my_array, [3,4]);
print "My Array Value = " . @{@my_array->[1]}[0] . "\n";
my $class = new TestClass(@my_array);
$class->print;
1;