in reply to Re: (tye)Re: Reference as the only Object element
in thread Reference as the only Object element
If you want to declare an object which is implented as a list, I'd do something like:
sub new { my $class = shift; my $self = [@_]; bless $self, $class; return $self; } sub getList { my $self = shift; if (wantarray) { return @$self; else { return [@$self]; } }
If you wanted to have a class which had only one attribute and that attribute was a list, I'd do something like:
Then, you would add setters as well. However, we already have something like this, in the form of tie and Tie::Array (and its cousin Tie::Hash). Check those out.sub new { my $class = shift; my $self = {}; bless $self, $class; $self->{LIST} = [@_]; return $self; } sub getList { my $self = shift; if (wantarray) { return @{$self->{LIST}}; else { return [@$self->{LIST}]; } }
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re2: Reference as the only Object element
by tye (Sage) on Nov 02, 2001 at 23:10 UTC | |
by dragonchild (Archbishop) on Nov 02, 2001 at 23:22 UTC |