在perl中匿名数组用方括号[]来表达,匿名数组数组用大括号{}来表达, 我们可以用ref函数来验证结果:
print "anonymous variable :", ref [],"
";#ARRAY
print "anonymous variable :", ref {},"
";#HASH
ARRAY
HASH
我们可以在类构造函数中定义匿名数组和匿名hash,作为特殊的成员变量使用,有需要时,在指定key和val,代码如下:
sub new{
my $class = shift;
my $self = {};
#定义数组和hash
$self->{'msg_hash'} = {};
$self->{'msg_arr'} = [];
bless $seft, $class ;
return $self;
}