Only if the object in question is a blessed hash reference. A Perl object is simply a blessed referent - you can also bless arrays, subroutines, regexes, and even scalars. See Blessables -- What Can You Make Into Objects? for more on that.
Back to your array ref - meditate on the following code: a class is defined with a single attribute (an array ref) and two accessor methods - one that returns a copy of the array ref and one that returns a copy of the array. Various methods of trying to change the attribute are attempted, but the only one that works is the last one, which assigns a new array ref explicitly.And please note that i 'abbreviated' this object's methods only for the sake of brevity. Please don't use this style in production code. :)use strict; my (@array,$array); my $foo = foo->new(); # won't change @array = $foo->get_array; @array = ('a'..'f'); print join(',',$foo->get_array),"\n"; # won't change $array = $foo->get_array_ref; $array = [('a'..'f')]; print join(',',$foo->get_array),"\n"; # won't change $array = $foo->{_array}; $array = [('a'..'f')]; print join(',',$foo->get_array),"\n"; # will change $foo->{_array} = [('a'..'f')]; print join(',',$foo->get_array),"\n"; package foo; use strict; sub new { bless { _array => [(0..9)] }, shift } sub get_array { @{shift->{_array}} } sub get_array_ref { shift->{_array} }
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In reply to (jeffa) Re: Storing arrays as object variables
by jeffa
in thread Storing arrays as object variables
by Basilides
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |