? |
标量 |
数组 |
散列 |
函数 |
定义符号 |
$ |
@ |
% |
& |
定义 |
$test |
@test |
%test |
Sub test |
使用 |
$test = ‘a’ |
@test = (1,2,3) |
%test = (‘a’=>1,’b’=>2) |
Sub test{ code } |
元素/使用 |
- |
$test[n] |
$test{key} |
&test(param) |
元素符号 |
- |
[..] |
{..} |
(..) |
引用 |
/$test |
/@test |
/%test |
/&test |
*引用1 |
*test{SCALAR} |
*test{ARRAY} |
*test{HASH} |
*test{CODE} |
解引用 |
符号解 |
${/$test} |
@{/@test} |
%{/%test} |
&{/&test} |
箭头解 |
- |
$test->[n] |
$test->{key} |
$test->(param) |
$ 解 |
- |
${/@test}[n] |
${/%test}{key} |
- |
匿名创建 |
- |
?$test=[1,3,4] |
$test={‘a’=>1,’b’=>2} |
$test=sub{ code } |
?
1. 传递文件句柄时,*号作为文件句柄的定义符号,例如
?
open (MYFILE, ">test.123" ); print? MYFILE? 123 ; splutter(*MYFILE); #?? /*MYFILE = *MYFILE close (MYFILE); sub?splutter?{ my? $fh?=? shift $fh? "her?um?well?a?hmmm/n" } |
2. 隐藏的箭头: 每一对花括号或方括号之间,隐藏着一个 ->?,包括 {}[] 或者 []{},下面的例子
?
#!perl?-w
use?strict;
my?$ref_to_AoA?=?[
????[?"fred",?"barney",?"pebbles",?"bamm?bamm",?"dino"],
????[?"homer",?"bart",?"marge",?"maggie"],
????[?"george",?"jane",?"elroy",?"judy"],
];
my?@Aoa?=?(
??????["fred",?"barney"],
??????["george",?"elroy"],
??????["homer",?"bart"],
??????{"test"=>"aaa","test2"=>"bbb"}
);
print?$ref_to_AoA->[2][3]; # 等价于?$ref_to_AoA->[2]->[3];
print?$Aoa[3]{"test"}; # 等价于 $Aoa[3]->{"test"}
?