##################################################### ## Class Constructor ##################################################### sub new { my $prototype = shift; my $class = ref $prototype || shift; # This will handle both types of constructor. my $self = { count => 0, name => '', age => 0 }; # No need to use int() in Perl. # Also, quotes are not needed to the left of => # (so long as it's alphanumeric) # Note that the quotes are required above, so that # perl can distinguish between '@persons' (a string) and # @persons (a nonexistant variable) # No need to use temporary variables here in Perl. # In fact, very rarely need to use them at all. if (@_) # are there more parameters? { $self->name(shift); } if (@_) # yet more? { $self->age(shift); } }