undef 
undef EXPR
undefundef is the name by which we refer to the abstraction known as “the
undefined value”. Conveniently, it also happens to be the name of a
function that always returns the undefined value. We happily confuse the
two.[255]
Coincidentally, the undef
function can also explicitly undefine an entity if you supply its name
as an argument. The EXPR argument, if
specified, must be an lvalue. Hence, you may only use this on a scalar
value, an entire array or hash, a subroutine name (using the & prefix), or a typeglob. Any storage
associated with the object will be recovered for reuse (though not
returned to the system, for most operating systems). The undef function will probably not do what you
expect on most special variables. Using it on a read-only variable like
$1 raises an exception.
The undef function is a unary
operator, not a list operator, so you can only undefine one thing at a
time. Here are some uses of undef as
a unary operator:
undef $foo;
undef $bar{"blurfl"}; # Different from delete $bar{"blurfl"};
undef @ary;
undef %hash;
undef &mysub;
undef *xyz; # destroys $xyz, @xyz, %xyz, &xyz, etc.Without an argument, undef is
just used for its value:
select(undef, undef, undef, $naptime); return (wantarray ? () : undef) if $they_blew_it; return if $they_blew_it; # same thing
You may use undef as a placeholder on the left side of a list assignment, in which case the corresponding ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access