当前位置:首页 » Perl » perl undef()函数

perl undef()函数

perl undef()函数例子,undef()函数实例代码 - 取消定义EXPR的值,使用一个标量,列表,哈希函数,或类型团。

语法

undef EXPR

undef


定义和用法

取消定义EXPR的值,使用一个标量,列表,哈希函数,或类型团。 使用的哈希为undef $hash{$key}这样的语句; 实际上是设置一个未定义的值指定的键的值。 如果你想删除的哈希中的元素,使用删除功能。

返回值

  • undef


例子

#!/usr/bin/perl -w
#by www.gitbook.net

$scalar = 10;
@arrary = (1,2);

print "1 - Value of Scalar is $scalar\n";
print "1 - Value of Array is @array\n";

undef( $scalar );
undef( @array );

print "2 - Value of Scalar is $scalar\n";
print "2 - Value of Array is @array\n";

这将产生以下结果:

1 - Value of Scalar is 10
1 - Value of Array is
Use of uninitialized value in concatenation (.) or 
                         string at test.pl line 13.
2 - Value of Scalar is
2 - Value of Array is