in reply to Count number of occurrences of a list of words in a file
In the the three solutions that where posted, everyone uses 'exists $hash{key}' and a '$hash{key}=...' and to me these look like two look-ups in the hash to me. Is this efficient? Can this be more efficient?
Athanasius
++$count{$word} if exists $count{$word};Tux
$cnt{$_}++ for grep { exists $cnt{$_} } m/(\w+)/g;AnomalousMonk
exists $count{$_} and ++$count{$_} for $line =~ m{ $rx_word }xmsg;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Count number of occurrences of a list of words in a file
by Cristoforo (Curate) on May 09, 2018 at 22:28 UTC | |
Re^2: Count number of occurrences of a list of words in a file
by AnomalousMonk (Archbishop) on May 09, 2018 at 22:27 UTC |