undef
EXPR
undef
This function undefines the value of
EXPR
, which must be an lvalue. Use only on a scalar value, an entire array or hash, or a subroutine name (using the
&
prefix). Any storage associated with the object will be recovered for reuse (though not returned to the system, for most versions of UNIX). The
undef
function will probably not do what you expect on most special variables.
The function always returns the undefined value. This is useful because you can omit the
EXPR
, in which case nothing gets undefined, but you still get an undefined value that you could, for instance, return from a subroutine to indicate an error. Here are some uses of
undef
as a unary operator:
undef $foo; undef $bar{'blurfl'}; undef @ary; undef %assoc; undef &mysub;
Without an argument, undef is just used for its value:
return (wantarray ? () : undef) if $they_blew_it; select(undef, undef, undef, $naptime);
You may use undef as a placeholder on the left side of a list assignment, in which case the corresponding value from the right side is simply discarded. Apart from that, you may not use undef as an lvalue.