Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

undef

Produces the undefined value, or undefines an existing variable.

Operates in three modes determined by op flags:

  • MOD (lvalue placeholder): Used in list assignment patterns like my (undef, $x) = @list. Adds a sentinel to lvalue_targets so pp_aassign skips that position.
  • STACKED (function call undef $x): Pops the target from the stack and undefines it. For arrays and hashes this clears the container; for hash/array element targets it sets the element to undef; for scalars it writes undef through the alias.
  • Default: If targ is set, sets the corresponding pad slot to undef. Always pushes undef onto the stack as the return value.

Synopsis

my $x = undef;
undef $x;                    # set $x to undef
undef @array;                # clear the array
undef %hash;                 # clear the hash
my (undef, @rest) = @list;   # skip first element in list assignment

See Also

defined