|
在使用模块的时候,有几个符号我很迷惑,请不吝赐教:
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;
}
这两个强调出来的语块中->又有什么作用? |
|