例1:
復制代碼 代碼如下:
#!/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:
復制代碼 代碼如下:
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";}
在定義變量時一定要初始化,或者在使用時判斷是否defined,很多的時候還需要判斷是否為空字符串。 特別是在使用getopt::long或cgi->query獲得參數(shù)后要檢測是否定義,如果么有定義考慮給予默認值。
您可能感興趣的文章:- C++中結構體的類型定義和初始化以及變量引用
- 基于C++全局變量的聲明與定義的詳解
- c語言全局變量和局部變量問題及解決匯總
- C++的static關鍵字及變量存儲位置總結
- 關于C++靜態(tài)成員函數(shù)訪問非靜態(tài)成員變量的問題
- C++中指向結構體變量的指針
- php 靜態(tài)變量的初始化
- 深入理解final變量的初始化
- 淺談Java變量的初始化順序詳解
- 詳解C++中變量的初始化規(guī)則