Science, Tech, Math › Computer Science Perl Array Splice() Function A quick tutorial on how to use it Share Flipboard Email Print AAGAMIA/The Image Bank/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 27, 2019 The Perl splice function takes the following form: Perl's splice() function is used to cut out and return a chunk or portion of an array. The portion that is cut out starts at the OFFSET element of the array and continues for LENGTH elements. If the LENGTH is not specified, it will cut to the end of the array. Example of the Perl Splice Function Think of the @myNames array as a row of numbered boxes, going from left to right, numbered starting with a zero. The splice() function would cut a chunk out of the @myNames array starting with the element in the #1 position (in this case, Michael) and ending 3 elements later at Matthew. The value of @someNames then becomes ('Michael', 'Joshua', 'Matthew'), and @myNames is shortened to ('Jacob', 'Ethan', 'Andrew'). Using the Optional 'REPLACE_WITH' As an option, you can replace the portion removed with another array by passing it in the REPLACE_WITH argument. In the above example, the splice() function would cut a chunk out of the @myNames array starting with the element in the #1 position (in this case, Michael and ending 3 elements later at Matthew. It then replaces those names with the contents of the @moreNames array. The value of @someNames then becomes ('Michael', 'Joshua', 'Matthew'), and @myNames is changed to ('Jacob', 'Daniel', 'William', 'Joseph', 'Ethan', 'Andrew'). You might want to check out some other Perl array functions such as reverse() to reverse the order of your array. Cite this Article Format mla apa chicago Your Citation Brown, Kirk. "Perl Array Splice() Function." ThoughtCo, Aug. 26, 2020, thoughtco.com/perl-array-splice-function-quick-tutorial-2641163. Brown, Kirk. (2020, August 26). Perl Array Splice() Function. Retrieved from https://www.thoughtco.com/perl-array-splice-function-quick-tutorial-2641163 Brown, Kirk. "Perl Array Splice() Function." ThoughtCo. https://www.thoughtco.com/perl-array-splice-function-quick-tutorial-2641163 (accessed April 2, 2023). copy citation Featured Video