package Adres; sub new { my $prototype = shift; my $class = ref $prototype || shift; my $self = { '@persons' => [], # [] = arrayref; {} = hashref; () = list # a list like this must be an arrayref # (reference to an array) because a list () cannot # be held in an hash directly. street => '', }; bless $self, $class; return $self; } sub get_person_count { my $self = shift; return (scalar @{ $self->{'@persons'} }); } sub add_person { my $self = shift; while (@_) # allow adding multiple people { die "Error! $_ is not a Person object." unless (ref $_ && $_->isa('Person')); # note the magic clause "ref $x && $x->isa('Class')" # this catches child classes as well # and is similar in effect to the Java # expression "instanceof Class" push @{ $self->{'@persons'} }, $_; } }