4.2.8 unshift

由陣列頭部,置入一個元素:

#! /usr/bin/perl

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

$f1="A";

unshift @total, $f1;

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

也可以置入另一個陣列:

#! /usr/bin/perl

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

@t2=qw( John Marry Kenny );

unshift @total, @t2;

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