Science, Tech, Math › Computer Science Perl Array Shift() Function: Quick Tutorial Share Flipboard Email Print Manabu Ogasawara/Stockbyte/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 February 10, 2019 The shift() function in a Perl script takes the following syntax: Perl's shift() function is used to remove and return the first element from an array, which reduces the number of elements by one. The first element in the array is the one with the lowest index. It's easy to confuse this function with pop(), which removes the last element from an array. It also should not be confused with the unshift() function which is used to add an element to the beginning of an array. Example of Perl's Shift() 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 left. The shift() function would cut the element off the left side of the array, return it, and reduce the elements by one. In the examples, the value of $oneName becomes 'Larry', the first element, and @myNames is shortened to ('Curly', 'Moe'). 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 shift() function would shift the element off the top of the stack, return it, and reduce the size of the stack by one. Cite this Article Format mla apa chicago Your Citation Brown, Kirk. "Perl Array Shift() Function: Quick Tutorial." ThoughtCo, Jul. 31, 2021, thoughtco.com/perl-array-shift-function-quick-tutorial-2641153. Brown, Kirk. (2021, July 31). Perl Array Shift() Function: Quick Tutorial. Retrieved from https://www.thoughtco.com/perl-array-shift-function-quick-tutorial-2641153 Brown, Kirk. "Perl Array Shift() Function: Quick Tutorial." ThoughtCo. https://www.thoughtco.com/perl-array-shift-function-quick-tutorial-2641153 (accessed June 4, 2023). copy citation