加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl常量+多维数组+变量的初始化

发布时间:2020-12-16 00:16:22 所属栏目:大数据 来源:网络整理
导读:代码: ? use ?strict; ? use ?warnings; my ? $test ?=? " asdf " ; print ? " ${test}_test2n " ; # constant use ?constant?{ ????AAA?=? " aaa " , ????BBB=? " bbb " , ????MIN_TOTAL?=? 12 , ????SCORE_PASS?=? 90 , ????SCORE_RED?=? 70 , }; print


代码:

?

use ?strict;?
use?warnings;

my? $test?=? " asdf ";
print? " ${test}_test2n ";

# 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? " $a1n ";
my? $a2?=? undef;
print? " $a2n ";
if(! defined( $a1)){ print? " a1?is?not?definedn ";}
if(! $a2){ print? " a2?is?not?definedn ";}
my? $a3= '';
if (! $a3 ){ print? " a3?is?empty?stringn ;}??


在定义变量时一定要初始化,或者在使用时判断是否defined,很多的时候还需要判断是否为空字符串。 特别是在使用getopt::long或cgi->query获得参数后要检测是否定义,如果么有定义考虑给予默认值。

?

完!?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读