我有一个文件,其中包含我需要在给定字符串中匹配的子字符串。这些给定的字符串取自另一个具有实际数据的文件。这是 csv 文件中的一列。如果给定的字符串具有这些子字符串中的任何一个,它将被标记为 TRUE。Perl 最好的方法是什么?
到目前为止我所做的是这样的。似乎仍然存在一些问题:
#!/usr/bin/perl
use warnings;
use strict;
if ($#ARGV+1 != 1) {
print "usage: $0 inputfilename\n";
exit;
}
our $inputfile = $ARGV[0];
our $outputfile = "$inputfile" . '.ads';
our $ad_file = "C:/test/easylist.txt";
our %ads_list_hash = ();
our $lines = 0;
# Create a list of substrings in the easylist.txt file
open ADS, "$ad_file" or die "can't open $ad_file";
while(<ADS>) {
chomp;
$ads_list_hash{$lines} = $_;
$lines ++;
}
for(my $count = 0; $count < $lines; $count++) {
print "$ads_list_hash{$count}\n";
}
open IN,"$inputfile" or die "can't open $inputfile";
while(<IN>) {
chomp;
my @hhfile = split /,/;
for(my $count = 0; $count < $lines; $count++) {
print "$hhfile[10]\t$ads_list_hash{$count}\n";
if($hhfile[9] =~ /$ads_list_hash{$count}/) {
print "TRUE !\n";
last;
}
}
}
close IN;