Perl undef Function

Advertisements


Description

This function undefines the value of EXPR. Use on a scalar, list, hash, function, or typeglob. Use on a hash with a statement such as undef $hash{$key}; actually sets the value of the specified key to an undefined value.

If you want to delete the element from the hash, use the delete function.

Syntax

Following is the simple syntax for this function:

undef EXPR

undef

Return Value

This function returns undef.

Example

Following is the example code showing its basic usage:

#!/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";

When above code is executed, it produced following result:

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.


Advertisements
Advertisements