Hi Everyone,
I'm trying to write a class in Perl. One of the attributes is an array.
How can I get/set the values of the array? Usually, I get the value of other attributes using:
$obj->{att} = "something";
but now, since it is an array, how can I do that? Here is the code I wrote:
Then, when I try to assign some values to this array, it does not work:
Any suggestions or comments?
Thanks in advance
I'm trying to write a class in Perl. One of the attributes is an array.
How can I get/set the values of the array? Usually, I get the value of other attributes using:
$obj->{att} = "something";
but now, since it is an array, how can I do that? Here is the code I wrote:
Code:
package class_name;
use strict;
my @my_array;
1;
sub new {
my $self = {};
$self->{my_array} = undef;
bless($self);
return $self;
}
Then, when I try to assign some values to this array, it does not work:
Code:
$obj->{@my_array} = @another_array;
print $obj->{@my_array[2]};
Any suggestions or comments?
Thanks in advance