读 《C程序员精通Perl》http://book.douban.com/subject/1232075/ 2.4.4节 笔记
#!/usr/bin/perl
use strict;
use warnings;
my $name = "calf_man";
my $value;
if (defined($name)) {
print "The name is defined as $name\n";
}
if (not defined($value)) {
print "The value is not defined.\n";
}
#$name = undef;
undef($name);
#undef #name;
if (not defined($name)) {
print "The name is not defined.\n";
}运行结果:
[root@localhost perl_practice]# ./define.pl
The name is defined as calf_man
The value is not defined.
The name is not defined.
[root@localhost perl_practice]#
本文通过一个Perl脚本示例,介绍了如何定义变量并检查其是否已定义。使用defined函数来判断变量是否存在,并展示了如何使变量变为未定义状态。
1011

被折叠的 条评论
为什么被折叠?



