將一個或多個項目新增到陣列的尾端。
my @animals = ("cat");
push(@animals, "mouse"); # ("cat", "mouse")
my @colors = ("red");
push(@colors, ("blue", "green")); # ("red", "blue", "green")
傳回執行 push
後陣列中的元素數量。
my $color_count = push(@colors, ("yellow", "purple"));
say "There are $color_count colors in the updated array";
從 Perl 5.14 開始,一個實驗功能允許 push
接受一個純量表達式。此實驗已被視為失敗,並在 Perl 5.24 中移除。