Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

unshift

Prepends one or more values to the beginning of an array.

Prepends the listed values to the front of the array, preserving argument order: unshift(@a, 1, 2, 3) yields (1, 2, 3, @original). Array arguments are flattened. Returns the new number of elements. Internally, values are inserted in reverse order to achieve the correct final ordering.

Synopsis

unshift @array, $value;
unshift @array, $v1, $v2, $v3;
unshift @array, @more_values;
my $new_len = unshift @array, $value;

Implementation Notes

perl5 (pp.c:6436): prepend values to the beginning of an array. Returns new array length.

See Also

PP runtime: unshift | shift, push, pop, splice