我有两个文件:file1.txt
和file2.txt
. 两者都包含以下格式的行:
文件 1
name1:value1
文件2
name2:value2
我想检查是否value1
在list2
(在name2
字符串中)找到
我有这个功能:
#!/usr/bin/perl
use warnings;
use Parallel::ForkManager;
sub loadf($);
print "Starting main program\n";
my @list1 = loadf("list1.txt");
my @list2 = loadf("list2.txt");
my $workernum = 10;
open(OK, '>>', 'valid.txt');
open(ER, '>>', 'invalid.txt');
$pm = new Parallel::ForkManager($workernum);
my $cnt = 0;
foreach $line (@list1) {
$cnt++;
my $pid = $pm->start and next;
my @data1 = split(":", $line);
my $name1 = $data1[0];
my $value1 = $data1[1];
my @data2 = split(":", $list2);
my $name2 = $data2[0];
my $value2 = $data2[1];
if (/$value1/i ~~ @list2)
{
print OK $name1 . " - " . $value2 . "\n";
print " [+] Found: " . $name1 . " - " . $value2 . "\n";
}
else
{
print ER $name1 . "\n";
print " [x] Unknown: " . $name1 . " - " . $value1 . "\n";
}
$pm->finish;
}
close(OK);
close(ER);
print "\n*** Finished ***\n";
sub loadf($) {
my @file;
open(FILE, $_[0] . "\n") or die("[+] Couldn't open " . $_[0] . "\n");
@file = <FILE>;
close(FILE);
return @file;
}
__END__
这是行不通的。我究竟做错了什么 ?