< Perl Programming < Keywords
The shift keyword
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
shift ARRAY
shift EXPRESSION
shift
Example
unshift(@ARGV, '-e') unless $ARGV[0] =~ /^-/;
See also
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.