perl 如何判断变量为空

2024-11-16 18:59:37
推荐回答(2个)
回答1:

判消做断字符串是否为空一般用以下可以了:
if(!$str) {
print "this is an empty/undefined string\n "
}
如果你还想区别空串 " " 和未赋有效值的串可以缺桥磨用伏斗
if(!$str) {
if(defined $str) {
print "this is an empty string\n "

}
else {
print "this is an undefined string\n "
}
}

回答2:

dosomething() unless(defined $var);