我有一個文件,其中包含需要在給定字符串中匹配的子字符串。這些給定的字符串取自具有實際數據的另一個文件。這是一個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