Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1417143
  • 博文数量: 239
  • 博客积分: 5909
  • 博客等级: 大校
  • 技术积分: 2715
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-24 20:19
文章分类

全部博文(239)

文章存档

2014年(4)

2013年(22)

2012年(140)

2011年(14)

2010年(59)

我的朋友

分类:

2010-11-29 12:20:49

对$scalar的引用:

my $variable;
my $reference=\$variable;

对$scalar的解引用:

$$reference;


对@array的引用:

my @array;
my $reference=\@array;

对@array的解引用:

$$reference[element];
$reference->[element];
@$reference; #to access the whole array


对%hash的引用

my %hash;
my $reference=\%hash;

对%hash的解引用:

$$reference{'key'};
$reference->{'key'};
%$reference; #to access the whole hash


对函数的解引用:

&$function(arguments);
$function->(arguments);

对函数的引用:

sub function{}
my $function=\&function;



匿名数组:

my $array;
@$array=("a","b");
$$array[3]="c";
$array->[4]="d";
print @$array;


匿名函数:

my $reference=sub {};
&$reference(parameters);

or

sub function{}

${\function(parameters)};


ref函数返回相应的引用类型:

ref(\@array)=ARRAY;
ref(\%hash)=HASH;
ref(\&function)=CODE;
ref(\\@array)=REF;
ref(\*hash)=GLOB;


数组的数组:

$array[$i]->[$j];
$arrat[$i][$j]


引用不能作为hash中的键字。


${a}=$a;
${"a"}=$a; #是一个符号引用

如果不使用符号引用: use strict 'refs';使用:"no strict 'refs'";

$name="bam";

$$name=1; #$bam=1

$name->[0]=4; # @bam,$bam[0]=4

$name->{X}="Y";

@$name=(); # clear @bam

&$name; #call &bam


阅读(2788) | 评论(1) | 转发(1) |
给主人留下些什么吧!~~

chinaunix网友2010-11-30 10:57:34

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com