perl 面向对象 new方法
2016-07-14 20:10
274 查看
[root@wx03 test]# cat Scan.pm package Scan; sub new{ my $class = shift; my $self={ 'a'=>11, 'b'=>22, 'c'=>33 }; bless $self,$class; return $self; }; sub sum_all { my $self=shift; my ($c,$d,$e)=@_; return ($self->{a} + $self->{b} + $self->{c} + $c + $d + $e); }; 1; [root@wx03 test]# cat t12.pl unshift(@INC,"/root/test"); use Scan ; my $ua=Scan->new(); print $ua->sum_all(1,5,8); [root@wx03 test]# perl t12.pl 80[root@wx03 test]# /*****************new 方法不定义内容: [root@wx03 test]# cat Scan.pm package Scan; sub new{ my $class = shift; my $self={}; bless $self,$class; return $self; }; sub sum_all { my $self=shift; my ($c,$d,$e)=@_; return ( $c + $d + $e); }; 1; [root@wx03 test]# cat t12.pl unshift(@INC,"/root/test"); use Scan ; my $ua=Scan->new(); print $ua->sum_all(1,5,8); [root@wx03 test]# perl t12.pl 14[root@wx03 test]#
相关文章推荐
- html概括
- MFC知识点(DDX_Control 与 DDX_Text ,ON_COMMAND和ON_MESSAGE)
- MFC中,要实现某功能必须先将GDI对象选入设备描述表?
- C++中类与对象的讲解(通俗易懂)
- 尚学堂 JAVA DAY11 概念总结
- web项目设计中框架的数据流
- MySQL使用存储过程循环插入数据
- 区间选点问题---poj-1328
- 第一个网页框架(自己的百度)
- scanf()函数实现输入带有空格的字符串
- nodejs连接sqlserver数据库简单封装-mssql模块
- volatile的理解
- JZOJ4600 有标记技巧的链剖
- cs231n - assignment1- k-Nearest Neighbor Classifier 梯度推导
- cycleBtn 创建--UIButtonTypeRoundedRect
- 【js】关于 setTimeout(0)所引发的……
- Android 的坑!
- 5-28 猴子选大王 (20分)
- Fast R-CNN笔记
- Android面试汇总(百度+360+Tencent+淘宝+Qualcomm+HTC)