in reply to Writing a container module
Given that you don't really say how you want it to work, I'm going to just make a bunch of unwarranted assumptions - perhaps they'll be right.
First, you probably want the list method to be:
That assumption is that you were trying to retrieve it via code like:sub list { my $self = shift @_; my $key = shift @_; my $aref = $self->{$key}; return wantarray ? @$aref : $aref; }
my @population = $self->list("_population");
I'm also presuming you haven't tested (or tested very well) your remove function. I'm curious as to what happens if there is more than one object that equals the target. My guess is "no good". Much simpler is:
I'm also quite curious as to why you "shift @_" most of the time, but "shift" once. Since it's such a common idiom in perl, I'd suggest removing the @_ from all shift's.sub remove { my $self = shift; my $type = shift @_; my $target = shift @_; $self->{$type} = [ grep { $target ne $_ } @{$self->{$type}} ]; return; }
Of course, if this isn't the solution to your query, you'll need to be a bit more specific as to the problem.
|
|---|