in reply to Composition Examples Sought

All great answers but to answer your question more directly:

package Person; sub new { my $class = shift; my $type = ref($class) || $class; my $self = {}; $self->{name} = shift; $self->{password} = shift; $self->{realname} = shift; bless $self, $type; } package Monk; sub new { my $class = shift; my $type = ref($class) || $class; my $self = {}; $self->{person} = Person->new( @_ ); $self->{level} = 0; bless $self, $type; } sub promote { my( $self ) = shift; print "Brother ", $self->{person}{name}, " is getting some XP\n"; $self->{level}++; } 1;

-derby

Replies are listed 'Best First'.
Re: Re: Composition Examples Sought
by meatpopsicl3 (Initiate) on May 24, 2002 at 17:23 UTC
    /me has a bright light bulb floating above his head.
    Ahaaa! Now I see what's going on here.

    Thanks derby!!!

      This is what it looks like all together:
      #!/perl/bin/perl # package Person; sub new { my $class = shift; my $type = ref($class) || $class; my $self = {}; $self->{name} = shift; $self->{password} = shift; $self->{realname} = shift; bless $self, $type; } package Monk; sub new { my $class = shift; my $type = ref($class) || $class; my $self = {}; $self->{part1} = Person->new( @_ ); #One of the things things that +makes up a Monk is a Person $self->{level} = 0; bless $self, $type; } sub promote { my( $self ) = shift; print "Brother ", $self->{person}{name}, " is getting some XP\n"; $self->{level}++; } $monk1 = Monk::new("Monk","Darrel","mypass","Darrel Cusey"); print "Brother ", $monk1->{part1}{name}, " is level ", $monk1->{level} +,"\n"; promote($monk1); print "Brother ", $monk1->{part1}{name}, " is level ", $monk1->{level} +,"\n";;

      --
      I also like chicken.