目录

undef

描述 (Description)

此函数取决于EXPR的值。 在标量,列表,散列,函数或类型上使用。 在带有诸如undef $ hash {$ key}之类的语句的哈希上使用; 实际上将指定键的值设置为未定义的值。

如果要从哈希中删除元素,请使用delete函数。

语法 (Syntax)

以下是此函数的简单语法 -

undef EXPR
undef

返回值 (Return Value)

此函数返回undef。

例子 (Example)

以下是显示其基本用法的示例代码 -

#!/usr/bin/perl -w
$scalar = 10;
@array = (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 1 2
2 - Value of Scalar is 
2 - Value of Array is 
Use of uninitialized value $scalar in concatenation (.) or string at main.pl line 12.
↑回到顶部↑
WIKI教程 @2018