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:

Perl shift iterate Benchmark

This little Perl Benchmark shows that its better to iterate through an array as to manipulate via shift.For more about shift look at Perl array pop, push, shift, unshift.

We see its better to iterate as to shift from an array: