#!/usr/bin/perl use strict; package person; sub new { my $class = shift(@_); #my $self = { 'name' => 'Alice' }; my $self = { 'name' => shift }; bless($self, $class); return($self); } sub tellName { my($self)=$_[0]; print "$self->{'name'}.\n"; } sub introduce { my($self)=$_[0]; print "Hello, I'm "; #$self->tellName(); person::tellName($self); } 1; package child; our @ISA = qw(person); # inherits from person sub new { my $class = shift(@_); #my $self = $class->SUPER::new(); my $self = $class->SUPER::new(shift); #$self ->{'nickName'} = 'Billy The Kid'; $self ->{'nickName'} = shift; $self->{mom} = shift; $self->{dad} = shift; bless $self, $class; return $self; } sub tellName { my($self)=$_[0]; print "$self->{'nickName'}.\n"; } sub introduce { #my($self)=$_[0]; print "Hi, I'm "; my($self)=$_[0]; $self->SUPER::introduce(); print 'but they also call me '; $self->tellName; print "Here's my mom: "; #$self->SUPER::introduce(); $self->{mom}->introduce; print "Here's my dad: "; $self->{dad}->introduce; } 1; package main; my $mom = new person('Alice'); my $dad = person->new('Charlie'); $mom->introduce(); # that time it works. $dad->introduce; print "\n"; my $son = new child('Billy', 'Billy the Kid', $mom, $dad); $son->introduce(); #### Hello, I'm Alice. Hello, I'm Charlie. Hello, I'm Billy. but they also call me Billy the Kid. Here's my mom: Hello, I'm Alice. Here's my dad: Hello, I'm Charlie.