[转 - 改] Perl初级教程 (二)
【对于字符串】 $b = 'BB'; ? $a = $b . $c; # Concatenate $b and $c = BBCC ? 【Perl的赋值语句】 $a = $b; # Assign $b to $a
? $b = 'Pear';
? 【数组变量】 数组通过以0开始的索引进行访问,方括号内为索引值 @List = ("1",2,'3'); print @List; > 123 ? 【?数组 赋值/删减】? ? @List = ("1",'3',"Array"); @array = (5..15);?? #序列化列表5~15;print @List; print "n"; print @array; >123Array ? 56789101112131415 ? # push Statement. push(@List,"Added"); print @List; print "n"; push(@List,@array); print @List; >123Array ? 123Array56789101112131415 ? # pop Statement. ? @List = ("1","Array");
? > 14 ???123Array568910111213 ?? 13 ? ?# 数组也可以用来为多个标量进行赋值 ? @List = ("1",@array); ($e,$f,$a) = @List;???? ?# 按照数组顺序项给变量赋值。 print "n"; ? ? > 15 ?? 14 ???1 ?? 2 ?? 3 ? # 最后,你可能想知道列表中最后一个元素的索引值,可以用这个表达式: print $#List; > 12; ? ?($a,$b) = ($c,$d); # Same as $a=$c; $b=$d;($a,$b) = @food; # $a and $b are the first two items of @food.($a,@somefood) = @food; # $a is the first item of @food?, @somefood is a list of the?others.(@somefood,$a) = @food; # @somefood is @food and?$a is undefined. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |