The syntax forms of the pop function
The pop function is used to remove and return the last element of an array and is analogous with the strings chop function that removes the last character of a string.
The size of the array will be shortened by 1. For arrays, it is similar with shift function that removes the first element of an array and is opposite to push/unshift function that adds a list at the end/front of an array.
Please note that whereas the push function generally appends a list at the end of an array, the pop function removes only the last element of the array, and not a list of elements.
You can manipulate an array like a:
- stack by using together pop and push functions
- queue by using both pop and unshift functions
This function has two syntax forms:
The parentheses can be omitted.
If you use the second form where the array is omitted, then the pop function will be applied against some special arrays:
- @ARGV array in the main program
- @_ array if you use it within the lexical scope of a subroutine.