【发布时间】:2010-02-12 00:36:45
【问题描述】:
!C:\Perl\bin\perl.exe
use strict;
use warnings;
my $numArgs = $#ARGV + 1;
print "thanks, you gave me $numArgs command-line arguments.\n";
while (my $line = <DATA> ) {
foreach my $argnum (0 .. $#ARGV) {
if ($line =~ /$ARGV[$argnum]/)
{
print $line;
}
}
}
__DATA__
A
B
Hello World :-)
Hello World !
当我传递一个参数时,它运行良好。 比如我运行 test.pl A 或 test.pl B 或 **test.pl Hello"
当我传递两个参数时,它只工作一段时间。
成功:当我运行 test.pl A B 或 test.pl A Hello 或 **test.pl B Hello"
失败:当我运行 test.pl Hello World*
产生并输出重复行:
D:\learning\perl>t.pl Hello World
thanks, you gave me 2 command-line arguments.
Hello World :-)
Hello World :-)
Hello World !
Hello World !
D:\learning\perl>
如何解决?感谢您的阅读和回复。
[更新] 我不想打印重复的行。
【问题讨论】: