Questions about this topic? Sign up to ask in the talk tab.

Perl/Basics/Variables and Data Types/Helper Functions/Shift

From NetSec
Jump to: navigation, search

The shift() function is like the inverse of the pop() function and treats the array like a stack. In stead of popping from the top of the stack, this function operates against the bottom of the stack.

my @array = (0,1);
my $first_element = shift(@array); # $array[0] now contains one, and @array only contains one element
Warning: Executing shift() on an array will delete the lowest order array element, changing the index of all elements.