Science, Tech, Math › Computer Science Perl Array unshift() Function Tutorial Share Flipboard Email Print Fuse/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 Computer Science Expert B.A., Abilene Christian University Kirk Brown is a systems software engineer with expertise in Perl, PHP, Ruby, and Python. our editorial process Kirk Brown Updated March 08, 2019 Perl's unshift() function is used to add value or values onto the beginning of an array (prepend), which increases the number of elements. The new values then become the first elements in the array. It returns the new total number of elements in the array. It's easy to confuse this function with push(), which adds elements to the end of an array. Picture a row of numbered boxes, going from left to right. The unshift() function would add the new value or values on to the left side of the array, and increase the elements. In the examples, the value of @myNames becomes ('Larry', 'Curly', 'Moe'). The array can also be thought of as a stack—picture a stack of numbered boxes, starting with 0 on the top and increasing as it goes down. The unshift() function would add the value to the top of the stack, and increase the overall size of the stack. You can unshift() multiple values onto the array directly: Or by unshift()-ing an array: Cite this Article Format mla apa chicago Your Citation Brown, Kirk. "Perl Array unshift() Function Tutorial." ThoughtCo, Aug. 26, 2020, thoughtco.com/perl-array-unshift-function-quick-tutorial-2641154. Brown, Kirk. (2020, August 26). Perl Array unshift() Function Tutorial. Retrieved from https://www.thoughtco.com/perl-array-unshift-function-quick-tutorial-2641154 Brown, Kirk. "Perl Array unshift() Function Tutorial." ThoughtCo. https://www.thoughtco.com/perl-array-unshift-function-quick-tutorial-2641154 (accessed January 28, 2021). copy citation