我是
靠谱客的博主
敏感饼干,这篇文章主要介绍
Perl中的引用和解引用,现在分享给大家,希望可以做个参考。
对$scalar的引用:
| my $variable; my $reference=$variable; |
对$scalar的解引用:
对@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
|
转载于:https://www.cnblogs.com/zhangxz/archive/2013/01/01/2841738.html
最后
以上就是敏感饼干最近收集整理的关于Perl中的引用和解引用的全部内容,更多相关Perl中内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复