Array Operations and Slices
Explore Perl's array operations including push, pop, shift, unshift, splice, and the use of array slices. Understand how to manipulate arrays effectively in different contexts to write maintainable and efficient Perl code.
Array operations
Sometimes, an array is more convenient as an ordered, mutable collection of items than as a mapping of indices to values. Perl provides several operations to manipulate array elements.
The push and pop operators
The push and pop operators add and remove elements, respectively, from the tail of an array:
We may push a list of values onto an array, but we can only pop one at a
time. push returns the new number of elements in the array. ...