Perl push Function

Advertisements


Description

This function pushes the values in LIST onto the end of the list ARRAY. Used with pop to implement stacks.

Syntax

Following is the simple syntax for this function:

push ARRAY, LIST

Return Value

This function returns number of elements in new array.

Example

Following is the example code showing its basic usage:

#!/usr/bin/perl -w

$, = ",";
@array = ( 1, 2 );
print "Before pushing elements  @array \n";
push(@array, (3, 4, 5));
print "After pushing elements  @array \n";

When above code is executed, it produced following result

Before pushing elements  1 2
After pushing elements  1 2 3 4 5


Advertisements
Advertisements