Perl Programming/Keywords/shift

From Wikibooks, open books for an open world
Jump to navigation Jump to search
Previous: setsockopt Keywords Next: shmctl

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

Example[edit | edit source]

unshift(@ARGV, '-e') unless $ARGV[0] =~ /^-/;

See also[edit | edit source]

Previous: setsockopt Keywords Next: shmctl