Perl | Array pop() Function
pop() function in Perl returns the last element of Array passed to it as an argument, removing that value from the array. Note that the value passed to it must explicitly be an array, not a list.
Syntax:
pop(Array)Returns:
undef if list is empty else last element from the array.
Example 1:
#!/usr/bin/perl -w # Defining an array of integers @array = (10, 20, 30, 40); # Calling the pop function $popped_element = pop(@array); # Printing the Popped element print "Popped element is $popped_element"; # Printing the resultant array print "\nResultant array after pop(): \n@array"; |
chevron_right
filter_none
Output:
Popped element is 40 Resultant array after pop(): 10 20 30
Example 2:
#!/usr/bin/perl -w # Defining an array of strings @array = ("Geeks", "For", "Geeks", "Best"); # Calling the pop function $popped_element = pop(@array); # Printing the Popped element print "Popped element is $popped_element"; # Printing the resultant array print "\nResultant array after pop(): \n@array"; |
chevron_right
filter_none
Output:
Popped element is Best Resultant array after pop(): Geeks For Geeks
Recommended Posts:
- Perl | cos() Function
- Perl | ord() Function
- Perl | sin() Function
- Perl | uc() Function
- Perl | abs() function
- Perl | each() Function
- Perl | int() function
- Perl | hex Function
- Perl | exp Function
- Perl | chr() Function
- Perl | oct() Function
- Perl | tell() Function
- Perl | log() Function
- Perl | Useful Array functions
- Perl | Reverse an array
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.



