Science, Tech, Math › Computer Science How to Use the Perl Array Pop() Function Share Flipboard Email Print elenabs/Getty Images Computer Science Perl PHP Programming Python Java Programming Javascript Programming Delphi Programming C & C++ Programming Ruby Programming Visual Basic View More By Kirk Brown Kirk Brown Computer Science Expert B.A., Abilene Christian University Kirk Brown is a systems software engineer with expertise in Perl, PHP, Ruby, and Python. Learn about our Editorial Process Updated on August 21, 2019 When writing a Perl script you might find it handy to use the pop() function, which looks like this: Perl's pop() function is used to remove and return (or pop) the last element from an array, which reduces the number of elements by one. The last element in the array is the one with the highest index. It's easy to confuse this function with shift(), which removes the first element from an array. An Example of Using the Perl Pop() Function If you think of an array as a row of numbered boxes, going from left to right, it would be the element on the far right. The pop() function would cut the element off the right side of the array, return it, and reduce the elements by one. In the examples, the value of $oneName becomes 'Moe', the last element, and @myNames is shortened to ('Larry', 'Curly'). The array can also be thought of as a stack—picture of a stack of numbered boxes, starting with 0 on the top, and increasing as it goes down. The pop() function would pop the element off the bottom of the stack, return it, and reduce the elements by one. Cite this Article Format mla apa chicago Your Citation Brown, Kirk. "How to Use the Perl Array Pop() Function." ThoughtCo, Aug. 28, 2020, thoughtco.com/perl-array-pop-function-quick-tutorial-2641150. Brown, Kirk. (2020, August 28). How to Use the Perl Array Pop() Function. Retrieved from https://www.thoughtco.com/perl-array-pop-function-quick-tutorial-2641150 Brown, Kirk. "How to Use the Perl Array Pop() Function." ThoughtCo. https://www.thoughtco.com/perl-array-pop-function-quick-tutorial-2641150 (accessed June 11, 2023). copy citation