in reply to Perl beginner's issue with hash
$/ = undef;
It enables the "slurp mode", i.e. <FILE> reads the whole file into $_. But you then check
which only runs once.if (/$i/g)
You can fix it in several ways:
my $regex = join '|', map quotemeta, @ids; while (<FILE>) { $counts{$1}++ if /($regex)/; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Perl beginner's issue with hash
by Maire (Scribe) on Apr 23, 2020 at 11:50 UTC | |
by AnomalousMonk (Bishop) on Apr 23, 2020 at 14:50 UTC |