perl中shift 和unshift 操作

来源:互联网 发布:企业名录采集软件 编辑:程序博客网 时间:2024/05/21 09:10
####################################################################
# unshift 和shift 对一个数组的开头进行操作(数组的左端有最小下标的元素)。
# unshift 和shift,如果其数组变量为空,则返回undef。
####################################################################
#!/usr/bin/perl -w
@array = qw#one two three#;
$m = shift (@array); #$m 得到“one”, @array 现在为(“two”, “three”)
shift @array;    #@array 现在为(“three”)
shift @array;    #@array 现在为空
$n = shift @array;    #$n 得到undef, @arry 仍为空
unshift(@array,5);    #@array 现在为(5)
unshift @array,4;     #@array 现在为(4,5)
@others = 1..3;
unshift @array, @others; #array 现在为(1,2,3,4,5)