!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一个或test.pl乙或** test.pl你好”虽然和foreach混合回路问题
当我走过有两个参数,它的工作原理一段时间只
成功:当我运行test.pl AB或test.pl。你好或** test.pl乙:你好”
失败:当我运行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>
如何解决呢?感谢您的阅读和答复。
[更新] 我不想打印重复的行。
Hi Kemp。是的,如你所说。但我不想打印重复的行。谢谢。 – 2010-02-11 08:54:44
然后在'print'语句后面加上'last;'。 – 2010-02-11 08:56:50
它很有效。谢谢! – 2010-02-11 09:00:23