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)

 

shift ARRAY

如果省略了 ARRAY,那么该函数在子过程和格式的词法范围里移动 @_;
它在文件范围(通常是主程序)里移动 @ARGV。

相关文章:

  • 2021-08-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
  • 2022-12-23
  • 2021-09-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
相关资源
相似解决方案