Packge Mule; Use Base ("Horse", "donkey");
# Declare a superclass it is the abbreviation for the following: package Mule;
BEGIN {Our @ISA = ("Horse", "donkey"); require Horse; require donkey;}
Horse class: [root@wx03 test]# cat horse.pm package Horse;
BEGIN {Our @ISA = "critter"; Require critter;}; Sub New {my $invocant = shift; my $class = ref ($invocant) | | $invocant; my $self = {color = "bay", legs = 4, own
ER = undef, @_, # Overwrite previous properties};
Return bless $self, $class;
#return $self;
};
Sub Sum1 {$self =shift;
My $a =shift;
My $b =shift;
Return $a + $b + 7;
};
Our @arr =QW/1 2 3 4 5 6 7/;
Our%h1= (1,2,3,4,5,6,7,8);
1;
Critter class: [root@wx03 test]# cat critter.pm Package critter;
Sub New {My $self = {};
my $invocant = shift; My $class = ref ($invocant) | |
$invocant;
My ($name) =@_;
My $self = {"name" = + $name}; Bless $self, $class;
# use class name to bless () reference return $self;
};
Sub sum2 {$self =shift; My $a =shift;
My $b =shift;
return $a + $b;
};
Sub Fun1 {$self =shift;
My $a =shift;
My $b =shift;
return $a/$b;
} 1;
[root@wx03 test]# cat t10.pl unshift (@INC, "/root/test");
Use Horse;;
$ua =horse->new ();
#print "It s an object\n" if Universal::isa ($ua, ' UNIVERSAL ');
$code =horse->sum1 (4,5);
Print "\ $str is $code \ n";
$code =horse->sum2 (4,5);
Print "\ $str is $code \ n";
[root@wx03 test]# perl t10.pl $str is the $STR is 9 using use base instead: [Root@wx03 test]# cat horse.pm package Horse;
Use base QW (critter); Sub New {my $invocant = shift; my $class = ref ($invocant) | | $invocant; my $self = {color = "bay", legs = 4, own
ER = undef, @_, # Overwrite previous properties};
Return bless $self, $class;
#return $self;
};
Sub Sum1 {$self =shift;
My $a =shift;
My $b =shift;
Return $a + $b + 7;
};
Our @arr =QW/1 2 3 4 5 6 7/;
Our%h1= (1,2,3,4,5,6,7,8);
1;
[root@wx03 test]# cat t10.pl unshift (@INC, "/root/test"); UseHorse;;
$ua =horse->new ();
#print "It s an object\n" if Universal::isa ($ua, ' UNIVERSAL ');
$code =horse->sum1 (4,5);
Print "\ $str is $code \ n";
$code =horse->sum2 (4,5);
Print "\ $str is $code \ n";
[root@wx03 test]# perl t10.pl $str is $str is 9