in reply to Counting and Filtering Words From File
Try this. It does the lc() and the tr/// only once.
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11116620 use warnings; my @excluded = qw( a about although also an and another are as at be b +een before between but by can do during for from has how however in in +to is it many may more most etc ); local $/; my %count; $count{$_}++ for split ' ', (lc <>) =~ tr!-'@~,.()?*%/[]="!!dr; delete @count{@excluded}; print "$count{$_} $_\n" for sort { $count{ $b } <=> $count{ $a } || $a cmp $b } keys %count;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Counting and Filtering Words From File
by hippo (Archbishop) on May 10, 2020 at 10:42 UTC |