start page | rating of books | rating of authors | reviews | copyrights

Programming Perl

Programming PerlSearch this book
Previous: 3.2.107 pipe Chapter 3
Functions
Next: 3.2.109 pos
 

3.2.108 pop

pop 

ARRAY

 pop

This function treats an array like a stack - it pops and returns the last value of the array, shortening the array by 1. If ARRAY is omitted, the function pops @ARGV (in the main program), or @_ (in subroutines). It has the same effect as:

$tmp = $ARRAY[$#ARRAY--];

or:

$tmp = splice @ARRAY, -1;

If there are no elements in the array, pop returns the undefined value. See also push and shift . If you want to pop more than one element, use splice .

Note that pop requires its first argument to be an array, not a list. If you just want the last element of a list, use this:

(something_returning_a_list)[-1]


Previous: 3.2.107 pipe Programming Perl Next: 3.2.109 pos
3.2.107 pipe Book Index 3.2.109 pos