Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一段代码不能像我预期的那样工作。主要是定义的功能不起作用。
@jobs = qw[job1 undef job2]; if(defined($jobs[1])) { print "Job 1 is defined"; }
我得到输出
Job 1 is defined
显然$jobs[1]是undef。我错过了什么?
$jobs[1]
undef
由于您使用qw的是,您的代码相当于:
qw
@jobs = ("job1", "undef", "job2");
与行为不同$jobs[1]的字符串 "undef"也是如此。undef
"undef"
如果你想成为第二份工作,undef你可以这样做:
@jobs = ("job1", undef, "job2");
AFAIK 你无法使用qw.