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

shift

Removes and returns the first element of an array, shifting all remaining elements down by one index.

Removes the first element from the array, shifts all remaining elements down by one, and returns the removed element. Returns undef if the array is empty.

When the SPECIAL flag is set (bare shift without an explicit array), the implicit target depends on call context: inside a subroutine it reads from @_ (pad slot 0); at file scope it reads from @ARGV. Handles both regular Av and AliasedAv (the typical representation of @_).

Synopsis

my $val = shift @array;
my $arg = shift;          # shifts from @_ inside a sub, @ARGV at top level

See Also

unshift, pop, push, splice