📜  珀尔 |数组 pop()函数

📅  最后修改于: 2022-05-13 01:54:56.832000             🧑  作者: Mango

珀尔 |数组 pop()函数

Perl 中的 pop()函数返回作为参数传递给它的 Array 的最后一个元素,从数组中删除该值。请注意,传递给它的值必须明确地是一个数组,而不是一个列表。

示例 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";
输出:
Popped element is 40
Resultant array after pop(): 
10 20 30

示例 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";
输出:
Popped element is Best
Resultant array after pop(): 
Geeks For Geeks