perl 面向对象demo
生活随笔
收集整理的這篇文章主要介紹了
perl 面向对象demo
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Vsftp:/root/perl/17# cat Critter.pm
package Critter;
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;
Vsftp:/root/perl/17# cat a1.pl
unshift(@INC,"/root/perl/17");
use Critter;
use Data::Dumper;
$ed = Critter->new('name'=>'poddinns');
print $ed->{name};
print "\n";
print $ed->sum(4,5);
print "\n";
Vsftp:/root/perl/17# perl a1.pl
poddinns
9
轉載于:https://www.cnblogs.com/zhaoyangjian724/p/6198945.html
總結
以上是生活随笔為你收集整理的perl 面向对象demo的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ajax格式,需要指定交互的data类型
- 下一篇: 常用前端代码资源(转)