最近在自学PERL,平常工作中不常用,感觉书当时是看懂了,语法格式性的东西过后就忘,总结一下以备查询。
1、变量
my $volume1 = 10;
my $volume2 = 10.1;
my $volume3 = "hello world";
2、列表
my @list1 = ("sunny", 1, 99 );
my @list2 = qw {sunny alice apple };
3、数组
my $array[0] = 0; #1个元素了
my $array[1] = 1; #2个元素了
my $array[2] = 2; #3个元素了
my $array[99] = 99; #99个元素了
4、哈希(散列)
my $some_hash{"fred"} = "flintstone"; #哈希赋值
my $some_hash{"barney"} = "rubble";
%new_hash = %old_hash;
%some_hash = {"fred", "flintstone", "barney", "rubble"};
%some_hash = {
"fred" => "flintstone",
"barney" => "rubble",
};
print $some_hash{"fred"} ; #访问哈希元素
print $some_hash{"barney"} ;
print %some_hash; #访问整个哈希
(未完待续)