Skip navigation.
Home
Your source for Perl tips, howto's, faq and tutorials

remove and/or replace sections of an array

( categories: )

Use the 'splice' function. The syntax is:

splice @array, $offset, $length, @list

where:

  • @array is the target array
  • $offset is the starting array element to remove. The first element is 0. If '$offset' is negative it starts counting from the end of the array
  • $length is the number of array elements to remove
  • @list (optional) is a list of elements that will replace the element removed

return value:

In scalar context, 'splice' returns the last element removed. In list context returns the list of elements removed from the array.


Syndicate content