Perl Programming/Keywords/shift
Appearance
The shift keyword
[edit | edit source]shift shifts the first value of the array off and returns it, shortening the array by 1 and moving everything down. If the array is empty, undef is returned. Without ARRAY, it shifts @_ within the lexical scope of formats and subroutines.
From Perl 5.14 onward, shift can take a scalar EXPRESSION that must hold a reference to an unblessed array. The argument will be dereferenced automatically. This aspect of shift is considered highly experimental, and the exact behaviour may change in a future version of Perl.
Syntax
[edit | edit source] shift ARRAY
shift EXPRESSION
shift
Example
[edit | edit source]unshift(@ARGV, '-e') unless $ARGV[0] =~ /^-/;