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

- ADD A LIST OF ELEMENTS TO THE FRONT

unshift @array, @list;

NOTES:
- unshift returns the new number of elements in the array.
- @list is prepended as a whole; not one element at a time, so it does not behave exactly as a normal "push" operation in a stack.

- REMOVE THE FIRST ELEMENT

shift @array;

NOTES:
- shift returns the value of the discarded element
- if shift is applied on an empty array, it returns undef

- ADD A LIST OF ELEMENTS AT THE END

push @array, @list;

NOTE:
- push returns the new number of elements in the array

- REMOVE THE LAST ELEMENT

pop @array;

NOTES:
- pop returns the value of the discarded element
- if the array is empty, returns undef