package _Init; use strict; use warnings; sub new { my ($class, %args) = @_; my $self = bless { }, ref($class) || $class; $self->_init(%args); return $self; } 1; package Container; use _Init; @Container::ISA = qw(_Init); use strict; use warnings; sub _init { my ($self, %args) = @_; $self->{_default} = []; } sub add { my $self = shift @_; my $key = shift @_; my $target = shift @_; my $aref = $self->{$key}; push @$aref, $target; } sub addtype { my $self = shift @_; my $key = shift @_; $self->{$key} = []; } sub list { my $self = shift @_; my $key = shift @_; my $aref = $self->{$key}; #return $aref wont work as well #why is $aref broken? my $count = 0; foreach(@$aref) { print "$_\n"; $count++; } } sub remove { my $self = shift; my $type = shift @_; my $target = shift @_; my $aref = $self->{$type}; my $count = 0; foreach(@$aref) { if ($target eq $_) { splice @$aref, $count, 1; } $count++; } } 1; package main: $self = Container->new(); $self->addtype("_population"); $self->add("_population", $someobjref); $self->list("_population");