4.2.6 push

由陣列尾端,置入一個元素:

#! /usr/bin/perl

@total=(2, 4, 6, 1, 3, 5, "a", "b", "c");

$f2="d";

push @total, $f2;

print @total;
# 此時 @total 應為 (2, 4, 6, 1, 3, 5, "a", "b", "c", "d");

也可以置入另一個陣列:

#! /usr/bin/perl

@total=(2, 4, 6, 1, 3, 5, "a", "b", "c");

@t2=qw( John Marry Kenny );

push @total, @t2;

print @total;
# 此時 @total 應為 (2, 4, 6, 1, 3, 5, "a", "b", "c", "John", "Marry", "Kenny");