Perl push 函式



描述

此函式將 LIST 中的值壓入到列表 ARRAY 的末尾。與 pop 配合使用以實現堆疊。

語法

以下是該函式的簡單語法 -

push ARRAY, LIST

返回值

此函式返回新陣列中的元素數。

示例

以下示例程式碼演示了它的基本用法 -

#!/usr/bin/perl -w

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

當執行以上程式碼時,會產生以下結果 -

Before pushing elements  1 2
After pushing elements  1 2 3 4 5
perl_function_references.htm
廣告
© . All rights reserved.