perl function unshift

The unshift function in Perl is used to add one or more elements to the beginning of an array. It increases the array size and moves existing elements to make room for the new elements. Here's an example:

my @fruits = ("apple", "banana", "cherry");
unshift(@fruits, "orange", "pear");
print "@fruits\n";
Source:‮.www‬theitroad.com

Output:

orange pear apple banana cherry

In this example, we have an array @fruits with three elements ("apple", "banana", "cherry"). We use the unshift function to add two more elements ("orange", "pear") to the beginning of the array. The resulting array has five elements ("orange", "pear", "apple", "banana", "cherry") which are then printed to the console using print.