Perl array pop, push, shift, unshift

This is a notice about the array manipulation in Perl, but you should try to avoid to manipulate if you just could iterate troth the array, this is much faster, for this look at Perl shift iterate Benchmark.

 

pop

remove and return the last element of the array.

push

add an element to the end of the array.

shift

remove and return the first element of the array.

unshift

add an element to the start of the array.

 

Code example:

 

Prints this:

4 thoughts on “Perl array pop, push, shift, unshift”

Leave a Reply

Your email address will not be published.

10 − 3 =