Perl | push() Function

push() function in Perl is used to push a list of values onto the end of the array. push() function is often used with pop to implement stacks. push() function doesn’t depend on the type of values passed as list. These values can be alpha-numeric.

Syntax: push(Array, List)

Parameter:
Array: in which list of values is to be added
List: which is to be added using push function



Returns:
the number of elements in new array.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

#!/usr/bin/perl -w
  
# Original Array
@array = ( 10, 20, 30 );
  
# Printing Array elements
print "Original Array: @array \n";
  
# Calling push function to 
# add a list of elements
push(@array, (35, 40, 55));
  
# Printing Updated array elements
print "Updated Array: @array \n";

chevron_right


Output:

Original Array: 10 20 30 
Updated Array: 10 20 30 35 40 55 

 
Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

#!/usr/bin/perl -w
  
# Original Array
@array = ( 10, A, 30 );
  
# Printing Array elements
print "Original Array: @array \n";
  
# Calling push function to 
# add a list of elements
push(@array, (F, G, H));
  
# Printing Updated array elements
print "Updated Array: @array \n";

chevron_right


Output:

Original Array: 10 A 30 
Updated Array: 10 A 30 F G H 


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.