If so, you can still do that using a reference.@colour = ('yellow', 'red', 'purple');
Then you'd return $this->{colour} just like before, and it'd be an array reference just like in the other solutions.@{ $this->{colour} } = ('yellow', 'red', 'purple');
You can therefore think of the same thing two different ways. The other examples show the assignment of a reference to an anonymous array. The above might be said to be assigning to the array to which the scalar $this->{colour} refers. The ordering of the thoughts is different and the syntax is different. Yet the result is the same.
When I first started messing with references years ago, the version with @{ $scalar } on the left seemed simpler to grasp. That notation does not scale as nicely to more complex data structures as using the anonymous reference notations on the right of the assignment operator, though.
I personally find the array ref on the right as gwadej shows and Fletch mentions to be easier to read and less cluttered. You should definitely get used to stating things in that form, even if the one I presented helps you make the transition.
In reply to Re: array as attributes in OO perl
by mr_mischief
in thread array as attributes in OO perl
by IL_MARO
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |