The unshift()
function in Perl prepends elements to the beginning of an array in Perl.
unshift(Array, values)
Array
: This is the array we want to prepend some values to.
values
: These are the values or a value we want to prepend to the Array
array.
It returns the number of elements in the array.
# create an array@gnaam = ("Apple","Amazon", "Meta");print "Before push: \@coins = @gnaam\n";# push values to the arrayprint "After push: Number of elemets in \@gnaam =" , unshift(@gnaam, "Google","Netflix");print "\nAfter push: \@gnaam = @gnaam";
gnaam
.unshift()
method.unshift()
method to add elements to the array. Then, we print the number of elements using the print
statement.