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:
@array = (10, 20, 30, 40);
$popped_element = pop ( @array );
print "Popped element is $popped_element" ;
print "\nResultant array after pop(): \n@array" ;
|
Output:
Popped element is 40
Resultant array after pop():
10 20 30
Example 2:
@array = ( "Geeks" , "For" , "Geeks" , "Best" );
$popped_element = pop ( @array );
print "Popped element is $popped_element" ;
print "\nResultant array after pop(): \n@array" ;
|
Output:
Popped element is Best
Resultant array after pop():
Geeks For Geeks
Last Updated :
07 May, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...