Perl use base instead of @ISA

Source: Internet
Author: User
Tags require
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.