=over

=item shift ARRAY
X<shift>

=item shift

Removes and returns the B<first> element of an array. This shortens the
array by one and moves everything down.

    my @arr  = ('cat', 'dog');
    my $item = shift(@arr); # 'cat'

    # @arr is now ('dog');

Returns C<undef> if the array is empty.

B<Note:> C<shift> may also return C<undef> if the first element in the array
is C<undef>.

    my @arr  = (undef, 'two', 'three');
    my $item = shift(@arr); # undef

If ARRAY is omitted, C<shift> operates on the C<@ARGV> array in the main
program, and the C<@_> array in subroutines. C<shift> will operate on the
C<@ARGV> array in C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}> blocks.

Starting with Perl 5.14, an experimental feature allowed
L<C<shift>|/shift ARRAY> to take a
scalar expression. This experiment has been deemed unsuccessful, and was
removed as of Perl 5.24.

See also L<C<unshift>|/unshift ARRAY,LIST>, L<C<push>|/push ARRAY,LIST>,
and L<C<pop>|/pop ARRAY>.  L<C<shift>|/shift ARRAY> and
L<C<unshift>|/unshift ARRAY,LIST> do the same thing to the left end of
an array that L<C<pop>|/pop ARRAY> and L<C<push>|/push ARRAY,LIST> do to
the right end.

=back