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:

sub list { my $self = shift @_; my $key = shift @_; my $aref = $self->{$key}; return wantarray ? @$aref : $aref; }
That assumption is that you were trying to retrieve it via code like:
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:

sub remove { my $self = shift; my $type = shift @_; my $target = shift @_; $self->{$type} = [ grep { $target ne $_ } @{$self->{$type}} ]; return; }
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.

Of course, if this isn't the solution to your query, you'll need to be a bit more specific as to the problem.


In reply to Re: Writing a container module by Tanktalus
in thread Writing a container module by yoda54

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.