perl 传递对象到模块
perl 中的对象 就是引用 通过new方法传递数据结构给各个模块 [root@wx03 test]# cat x1.pm
package x1;
use Data::Dumper;
sub new {
my $self ={};
my $invocant = shift;
my $class = ref($invocant) || $invocant;
my ($name,$age,$starting_position,$monthly_salary)=@_;
my $self = {
"name" =>$name,
"age" =>$age
};
print "\$class is $class\n";
print "--------------------\n";
print $self->{name};
print "\n";
print "--------------------\n"; bless($self, $class); # 给予对象性质
print "\$self is $self\n";
$str=Dumper($self);
print "\$str is $str\n"; return $self;
}; sub sum_var {
my ($self,
$var1, # Name or IP number of host to ping
$var2, # Seconds after which ping times out
) = @_;
my $var3= $var1 + $var2;
return $var3;
}
1; [root@wx03 test]# cat a2.pl
unshift(@INC,"/root/test");
require x1;
$ed=x1->new('lily','29');
print "\n"; [root@wx03 test]# perl a2.pl
$class is x1
--------------------
lily
--------------------
$self is x1=HASH(0xd49310) ###perl里对象就是hash
$str is $VAR1 = bless( {
'name' => 'lily',
'age' => '29'
}, 'x1' ); -----------------------------------------------------
[root@wx03 test]# cat x1.pm
package x1;
use Data::Dumper;
sub new {
my $self ={};
my $invocant = shift;
my $class = ref($invocant) || $invocant;
my ($name,$age,$starting_position,$monthly_salary)=@_;
my $self = {
"name" =>$name,
"age" =>$age
}; bless($self, $class); # 给予对象性质 return $self;
}; sub sum_var {
my ($self,
$var1, # Name or IP number of host to ping
$var2, # Seconds after which ping times out
) = @_;
my $var3= $var1 + $var2;
return $var3;
}
1; [root@wx03 test]# cat x2.pm
package x2;
use Data::Dumper; sub sum_a {
my ($self, ##传入对象
$var1, # Name or IP number of host to ping
$var2, # Seconds after which ping times out
) = @_;
print "x2 module\n";
print $self->{name};
print "\n";
my $var3= $var1 + $var2 +99;
return $var3;
}
1;
[root@wx03 test]# cat a1.pl
unshift(@INC,"/root/test");
require x1;
require x2;
$ed=x1->new('lily','29');
print "----------------------\n";
print x2::sum_a($ed,90,66); ##传入对象到x2模块
print "\n"; [root@wx03 test]# perl a1.pl
----------------------
x2 module
lily
255
perl 传递对象到模块的更多相关文章
- Message和handler传递对象
Bundle可以传递对象,message又可以传递Bundle于是就可以利用buddle作为中间载体传递对象了 Message msg = Message.obtain(); Bundle b = ...
- Android 全局获取 Context 与使用 Intent 传递对象
=====================全局获取 Context======================== Android 开发中很多地方需要用到 Context,比如弹出 Toast.启动活 ...
- Android--Intent传递对象
Intent 传递对象通常有两种实现方式,Serializable 和 Parcelable: 一.Serializable:序列化,表示将一个对象转换成可存储或可传输的状态,序列化后的对象可以在网络 ...
- 实现在GET请求下调用WCF服务时传递对象(复合类型)参数
WCF实现RESETFUL架构很容易,说白了,就是使WCF能够响应HTTP请求并返回所需的资源,如果有人不知道如何实现WCF支持HTTP请求的,可参见我之前的文章<实现jquery.ajax及原 ...
- Android中如何使用Intent在Activity之间传递对象[使用Serializable或者Parcelable]
http://blog.csdn.net/cjjky/article/details/6441104 在Android中的不同Activity之间传递对象,我们可以考虑采用Bundle.putSeri ...
- Intent传递对象的两种方法(Serializable,Parcelable) (转)
今天讲一下Android中Intent中如何传递对象,就我目前所知道的有两种方法,一种是Bundle.putSerializable(Key,Object);另一种是Bundle.putParcela ...
- Intent传递对象的两种方法
Android为intent提供了两种传递对象参数类型的方法 分别需要使实体类实现Serializable接口.Parcelable接口 首先我们要知道,传递对象,需要先将对象序列化 一.那么为什么要 ...
- Android中Intent传递对象的两种方法(Serializable,Parcelable)
今天要给大家讲一下Android中 Intent中如何传递对象,就我目前所知道的有两种方法,一种是Bundle.putSerializable(Key,Object);另一种是 Bundle.putP ...
- 利用Bundle在activity之间传递对象
(2010-12-04 09:45:54) 转载▼ 标签: it 分类: android开发 转自:http://chen592969029.javaeye.com/blog/772656 假如需要在 ...
随机推荐
- HtmlUnit+Jsoup 解决爬虫无法解析执行javascript的问题
本人最近在研究爬虫.作为一个新手.研究了些爬虫框架,发现所有开源的爬虫框架很多,功能也很齐全,但唯独遗憾的是,目前还没有发现那个爬虫对js完美的解释并执行.看了浅谈网络爬虫爬js动态加载网页(二)之后 ...
- Java代码优化策略
1.生成对象时,合理分配空间和大小:new ArrayList(100); 2.优化for循环: Vector vect = new Vector(1000); For(int i=0; i<v ...
- 在一个数组中是否存在两个数A、B的和为M
#include <iostream>#include <algorithm>//#include <vector>using namespace std; int ...
- BZOJ 1800: [Ahoi2009]fly 飞行棋( 枚举 )
O(N2)算出有x条直径然后答案就是x(x-1)/2...这个数据范围是闹哪样! ----------------------------------------------------------- ...
- (Problem 57)Square root convergents
It is possible to show that the square root of two can be expressed as an infinite continued fractio ...
- Linux网卡设置
http://blog.chinaunix.net/uid-20149676-id-1733254.html
- 快速提取PROTEL99SE PCB文件上的封装方法
1.首先打开你要提取元件封装的PCB. 2.执行生成元件库的命令...软件会帮你把这个PCB上的所有元件生成一个临时库. 3.打开你自己的元件库... 4.PCB刚才生成的元件库中选中你所需要的元件, ...
- spring的定时执行代码 跑批
最近公司上线了抽奖的活动,活动需求 1:每天凌晨更新状态,实现自动开启和关闭活动 2:活动结束自动抽取中奖号码 在这里提供spring的定时调度功能 1:首先是配置文件 在你的web.xml中,查看配 ...
- poj 1731 Orders(暴力)
题目链接:http://poj.org/problem?id=1731 思路分析:含有重复元素的全排列问题:元素个数为200个,采用暴力枚举法. 代码如下: #include <iostream ...
- ThinkPHP - 关联模型 - 多对多
表结构: 映射关系: UserRelationModel会取UserRelation为表名称.所以要自定义表名称: //定义主表名称protected $tableName = 'User'; < ...