- 论坛徽章:
- 0
|
你的源程序存在点逻辑问题。。 在你的基础上稍微修改了下,应该能满足- #!/usr/bin/perl -w
- use strict;
- my $a="2.txt";
- my $b="1.txt";
- open IN1, $a or die "can't open $a";
- open IN2, $b or die "can't open $b";
- open OUT, '>', "out.txt" or die "can't open out.txt";
- my @data = <IN1>;
- sub func
- {
- my ($str, @arr) = @_;
- for (my $i=0; $i<=$#arr; ++$i)
- {
- chomp($arr[$i]);
- if ($str eq $arr[$i])
- {
- return 1;
- }
- }
-
- return 0;
- }
- my @names = <IN2>;
- foreach my $i (0..$#data){
- my @line2 = split(/\s+/,$data[$i]);
- my $name2 = shift @line2;
- print "name2:", $name2,"\n";
- if (func($name2, @names))
- {
- print OUT $data[$i];
- }
- }
- close IN1;
- close IN2;
- close OUT;
复制代码 |
|