perl 面向对象 new方法
2016-07-14 20:10
162 查看
[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]#
相关文章推荐
- 洛谷 P2296 [NOIP2014 D2T2] 寻找道路
- Google Guava中Preconditions的用法,让前置条件判断变得更优雅
- 基于GPU计算的贴图生成工具Knald
- UDP之丢包原因及具体问题分析
- JavaWEB小知识学习--验证码生成
- 数据库(学习整理)----3--Oracle创建表和设置约束
- git 恢复丢失的文件
- perl 面向对象 new方法
- perl 面向对象 new方法
- html概括
- MFC知识点(DDX_Control 与 DDX_Text ,ON_COMMAND和ON_MESSAGE)
- MFC中,要实现某功能必须先将GDI对象选入设备描述表?
- C++中类与对象的讲解(通俗易懂)
- 尚学堂 JAVA DAY11 概念总结
- web项目设计中框架的数据流
- MySQL使用存储过程循环插入数据
- 区间选点问题---poj-1328
- 第一个网页框架(自己的百度)
- scanf()函数实现输入带有空格的字符串
- nodejs连接sqlserver数据库简单封装-mssql模块