如何在严格的编译指示下将variables设置为NULL?

use strict; my $var = NULL; 

Bareword "NULL" not allowed while "strict subs" in use会产生Bareword "NULL" not allowed while "strict subs" in useBareword "NULL" not allowed while "strict subs" in use的错误

Perl中没有NULL。 但是,variables可以是undef ,这意味着它们没有设置值。
这里有一些如何在Perl中获取未定义variables的例子:

 my $var; # variables are undefined by default undef $var; # undef() undefines the value of a variable $var = undef; # same, using an alternative syntax 

要检查variables的defined() ,使用defined() ,即

 print "\$var is undefined\n" unless defined $var;