#!/usr/bin/perl use strict; use warnings; use Peasant; my $henry = Peasant->new(name => "Peasant1", hp => "15"); my $joe = Peasant->new(name => "Peasant2", hp => "15"); $joe->damage($henry->attack); $henry->damage($joe->attack); #### package Peasant; use strict; sub new { my ($class, %arg) = @_; my $objref = { _name => $arg{name} || "unknown", _hp => $arg{name} || "unknown" }; bless $objref, $class; return $objref; } sub damage { print "$_[0] damage\n"; $_[0]->{_hp} - $_[0]; } sub name { return $_[0]->{_name} } sub attack { my $int = int(rand(5)); print "$_[0]->{_name} attacks for $int.....\n"; return $int; } 1;