You are viewing the version of this documentation from Perl blead. This is the main development branch of Perl. (git commit ae4922d4ab80776fd244c80b2816378f4e4a63a8)
pop ARRAY
pop

Removes and returns the last element of the array, shortening the array by one element.

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

# @arr is now ('cat', 'dog')

Returns undef if the array is empty.

Note: pop may also return undef if the last element in the array is undef.

my @arr  = ('one', 'two', undef);
my $item = pop(@arr); # undef

If ARRAY is omitted, pop operates on the @ARGV array in the main program, but the @_ array in subroutines. pop will operate on the @ARGV array in eval STRING, BEGIN {}, INIT {}, CHECK {} blocks.

Starting with Perl 5.14, an experimental feature allowed pop to take a scalar expression. This experiment has been deemed unsuccessful, and was removed as of Perl 5.24.