perl中shift 和unshift 操作
2008-02-02 11:18:04| 分类: Perl语言|举报|字号 订阅
#################################################################### # 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) |
时间: 2024-08-07 08:20:05