LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1566|回复: 1

请教几个关于perl问题,已经迷惑我很久了

[复制链接]
发表于 2008-7-24 20:00:39 | 显示全部楼层 |阅读模式
在使用模块的时候,有几个符号我很迷惑,请不吝赐教:
package Bean;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(setBeanType);

sub new {
my $type = shift;
my $this = {};
$this->{'Bean'} = 'Colombian';
bless $this, $type;
return $this;
}
其中bless函数有什么用?它将返回什么东西,对整个函数有什么用?$this->{'Bean'} = 'Colombian'; ->是什么符号,有什么用?
用哈希表的代码如下:

sub new {
my $type = shift;
my %parm = @_;
###########################
my $this = {};
$this->{'Name'} = $parm{'Name'};
$this->{'x'} = $parm{'x'};
$this->{'y'} = $parm{'y'};
###############################
bless $this, $type;
}
用数组保存的代码如下:

sub new {
my $type = shift;
my %parm = @_;
#############################
my $this = [];
$this->[0] = $parm{'Name'};
$this->[1] = $parm{'x'};
$this->[2] = $parm{'y'};
##################################
bless $this, $type;
}
这两个强调出来的语块中->又有什么作用?
发表于 2008-7-29 18:45:25 | 显示全部楼层
看intermediate perl programming
看里面的引用
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表