我正在开发一个程序,该程序从 CSV 文件中获取信息作为源,以通过具有“客户包”的文本文件进行搜索。我只对某些条目进行了奇怪的计数,我似乎无法弄清楚是什么导致了重复计数。谁能查看我的代码并告诉我我的逻辑/语法是否关闭?(可能是)。我想要完成的只是计算 csv 文件中条目的文本文件中的总出现次数(packageid,package_description)
谢谢您的帮助!我在这里发疯了。
#!/usr/bin/perl
use strict;
use Text::CSV;
# Variables already declared in the other PL file ** Remove if consolidating **
my $file2 = 'master_plist.csv';
my $csv2 = Text::CSV->new(); # Create a Text::CSV object
open (CSV2, "<", $file2) or die $!; #open CSV file for parsing
while (<CSV2>) {
if ($csv2->parse($_)) {
my @columns2 = $csv2->fields(); # Parse CSV and load into an array for each row.
my $packID = $columns2[0];
my $packDESC = $columns2[1];
my $val = 'customer_packages_report.txt';
chomp ($val);
my $cnt=0;
open (HNDL, "$val") || die "wrong filename";
while ($val = <HNDL>)
{
while ($val =~ /$packID - $packDESC/ig)
{
$cnt++;
}
}
#if ($packDESC =~ /\(/g) {
# $packDESC =~ s/\(/\(/g;
#}
print "Total iterations of $packDESC: $cnt\n";
close (HNDL);
# End original code
} # Close IF
} # Close WHILE
close CSV;