The push and shift functions

The push function adds a variable or a list of variables to the end of a given array.


$a = 5;
$b = 7;
@array = ("David", "John", "Gadi");
push (@array, $a, $b);

# @array is now ("David", "John", "Gadi", 5, 7)

The shift function removes the first element of a given array and returns this element.


@array = ("David", "John", "Gadi");
$k = shift (@array);

# @array is now ("John", "Gadi");
# $k is now "David"

Note that after both the push and shift operations the given array @array is changed!

Table of Contents.
Previous | Next.