perl function push

htt‮www//:sp‬.theitroad.com

The push function in Perl is used to add one or more elements to the end of an array. It takes one or more values as arguments and appends them to the end of the array.

Here's an example:

# create an array
my @fruits = ('apple', 'banana', 'orange');

# add an element to the end of the array
push @fruits, 'pear';

# add multiple elements to the end of the array
push @fruits, 'peach', 'grape';

# print the contents of the array
print "Fruits: @fruits\n";

Output:

Fruits: apple banana orange pear peach grape

In the example above, the push function is used to add the elements 'pear', 'peach', and 'grape' to the end of the @fruits array. The resulting array is then printed to the console using print.