- 论坛徽章:
- 0
|
本帖最后由 addbe 于 2010-03-11 23:49 编辑
以下是我的代码- #! /usr/bin/perl -w
- foreach (@ARGV){
- print "@ARGV\n";
- print "hello $_\n";
- print "begin !@ARGV\n";
- if (/(-\w)/){
- print "# !$_!\n";
- push @options,$_;
- $a=shift (@ARGV);
- print "a is $a\n";
- print "options are @options\n";
- }
- print "\n";
- print "options are @options\n";
- print "end @ARGV\n";
- print "#######\n";
- }
- print "@options\n";
- print "@ARGV\n";
复制代码 运行的结果是 perl 3.pl -a -s 1 2
-a -s 1 2
hello -a
begin !-a -s 1 2
# !-a!
a is -a
options are -a
options are -a
end -s 1 2
#######
-s 1 2
hello 1
begin !-s 1 2
options are -a
end -s 1 2
#######
-s 1 2
hello 2
begin !-s 1 2
options are -a
end -s 1 2
#######
-a
-s 1 2
foreach不是说是逐个取元素么?为啥-s没有去取? |
|