#!/usr/bin/perl -w
#下面定義了三個數組
$test[0] = 'black';
$test[1] = "gteen";
$test[2] = "red";
print qq/打印自定義的三個數組:\n/;
print "@test\n";
print @test,"\n";
#上面的打印, 說明加""與不加是有區別的, 加了的話默認在元素中加空格
print q/打印$test[10]的結果:/;
print "$test[10]";
if (defined($test[10])){
print "not undef\n";
}
else{
print "undef\n"
}
#結果爲未定義的undef
#以上定義了$test[10], 所以數組自動擴充爲11個元素, 沒有指定值的自動被賦爲undef
print "數組的元素個數爲:";
$count = $#test+1;
print $count, "\n";
#對於數組@test, 最後一個元素的索引爲$#test, 所以$#test+1爲數組的長度
~
~
~
PERL語言入門:第三章:列表與數組:訪問數組元素與特殊索引
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.