centos6.5:/root/podinns/lib#cat First.pm package First; use base qw(Second); sub new { my $self = {}; my $invocant = shift; my $class = ref($invocant) || $invocant; my ($name)=@_; my $self = { "name" =>"luotuo", @_ # 覆盖以前的属性 }; bless $self, $class; # Use class name to bless() reference return $self; }; sub sum { $self=shift; my $a=shift; my $b=shift; return $a + $b; }; 1; centos6.5:/root/podinns/lib#cat Second.pm package Second; sub sum_all { $self=shift; my $a=shift; my $b=shift; return $a * $b; }; sub sum_x { my $a=shift; my $b=shift; return $a * $b; }; 1; centos6.5:/root/podinns/lib#cat a2.pl unshift(@INC,"/root/podinns/lib"); use First; $ed=First->new('name'=>'poddinns'); print "111111111111111\n"; print $ed->sum(12,34); print "\n"; print "2222222222222222\n"; print $ed->sum_all(12,34); print "\n"; print "333333333333333333\n"; print Second::sum_x(12,21); print "\n"; centos6.5:/root/podinns/lib#perl a2.pl 111111111111111 46 2222222222222222 408 333333333333333333 252
perl use base 继承
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
python多态继承
python继承
构造函数 多重继承 Python -
Perl 面向对象之基类(use base)
Perl 面向对象之基类(use base)
Perl perl 数组 多继承 面向对象