我有一个文件,其中包含需要在给定字符串中匹配的子字符串。这些给定的字符串取自具有实际数据的另一个文件。这是一个csv文件中的列。如果给定的字符串有任何这些子字符串,它将被标记为TRUE。什么是最好的方法是Perl?从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;
@Ed我已经把我做的代码。但是仍然存在一些错误。但它有很多错误。 – sfactor