我不能从你最后的评论中看出你是否还在做这件事。无论如何,这是一个需要考虑的解决方案。
use strict;
use warnings FATAL => 'all';
use autodie qw(:all);
# slurp files into arrays
open my $RECORDSFILE, '<', 'searchme.csv';
my @records = <$RECORDSFILE>;
close $RECORDSFILE;
open my $LISTFILE, '<', 'list.csv';
my @citychecklist = <$LISTFILE>;
close $LISTFILE;
open my $NEWFILE, '>>', 'new.csv';
my $cityidx = 2;
my $item;
my $record;
# loop through each record and extract the city string
foreach $record (@records) {
my @data = split qr/,/, $record;
my $city = $data[$cityidx];
# skip the header
next if $city eq 'city';
# compare the city string with each city in our other list
foreach $item (@citychecklist) {
chomp $item;
# if we find a match write out the record to another file
if ($city eq $item) {
print {$NEWFILE} $record;
}
}
}
close $NEWFILE;