亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

perl常量、多維數(shù)組及變量的初始化的實(shí)例代碼

 更新時(shí)間:2013年02月09日 20:33:18   作者:  
perl常量、多維數(shù)組及變量的初始化的例子,供大家學(xué)習(xí)參考

例1:

復(fù)制代碼 代碼如下:

#!/usr/bin/perl
use strict;
use warnings;
my $test = "asdf";
print "${test}_test2\n";
#constant
use constant {
    AAA => "aaa",
    BBB=> "bbb",
    MIN_TOTAL => 12,
    SCORE_PASS => 90,
    SCORE_RED => 70,
};
print AAA;
print SCORE_PASS;
#two dimesion arrays
my @steps = (
      ["aaa", "aaavalue"],
      ["bbb","bbbvalue"],
      ["ccc","cccvalue"]
);
print "\n";
foreach my $i (0 .. $#steps){
  print "$steps[$i][0]:$steps[$i][1]\n";
}

代碼2:

復(fù)制代碼 代碼如下:

my $a1;
print "$a1\n";
my $a2 = undef;
print "$a2\n";
if(!defined($a1)){print "a1 is not defined\n";}
if(!$a2){print "a2 is not defined\n";}
my $a3='';
if(!$a3){print "a3 is empty string\n";}

在定義變量時(shí)一定要初始化,或者在使用時(shí)判斷是否defined,很多的時(shí)候還需要判斷是否為空字符串。 特別是在使用getopt::long或cgi->query獲得參數(shù)后要檢測(cè)是否定義,如果么有定義考慮給予默認(rèn)值。

相關(guān)文章

最新評(píng)論