Copyright © tutorialspoint.com

# PERL undef Function

## Syntax

undef EXPR undef

## Definition and Usage

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.

## Return Value

- undef

## Example

    #!/usr/bin/perl -w

    $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";

It will produce following results:

    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

Copyright © tutorialspoint.com