CSV ファイルを解析して、他のすべての郵便番号を読み取ろうとしています。各キーが郵便番号で、値がファイルに表示される番号であるハッシュを作成しようとしています。次に、内容を郵便番号-番号として印刷したいと思います。これが私がこれまでに持っているPerlスクリプトです。
use strict;
use warnings;
my %hash = qw (
zipcode count
);
my $file = $ARGV[0] or die "Need CSV file on command line \n";
open(my $data, '<', $file) or die "Could not open '$file $!\n";
while (my $line = <$data>) {
chomp $line;
my @fields = split "," , $line;
if (exists($hash{$fields[2]})) {
$hash{$fields[1]}++;
}else {
$hash{$fields[1]} = 1;
}
}
my $key;
my $value;
while (($key, $value) = each(%hash)) {
print "$key - $value\n";
}
exit;