Perl (Scripting) - Remove element beginning of array (shift)

by
Jeremy Canfield |
Updated: March 23 2021
| Perl (Scripting) articles
Let's take for example the following array.
my @fruit = qw(banana apple orange grapes);
Printing the array will print all of the values in the array.
banana apple orange grapes
Shift can be used to remove values from the beginning of the array. In this example, "banana" is removed from the @fruit array.
shift @fruit;
Printing the array will show that "banana" has been removed from the array.
apple orange grapes
If needed, you can store the items being removed from the array in a variable.
$banana = shift @fruit;
Pop can be used to remove values from the end of an array.
Unshift can be used to append values to the beginning of an array.
Push can be used to append vaues to the end of an array.
Did you find this article helpful?
If so, consider buying me a coffee over at