Word frequency: Difference between revisions

m
→‎{{header|Perl 6}}: more concisely
m (→‎{{header|Perl 6}}: Remove some unnecessary interim variables)
m (→‎{{header|Perl 6}}: more concisely)
Line 49:
( Really, a better regex would allow for contractions and embedded apostrophes but that is beyond the scope of this task. There are words like cat-o'-nine-tails and will-o'-the-wisps in there too to make your day even more interesting. )
 
<lang perl6>sub MAIN ($filename, $counttop = 10) {
.say for ($filename.IO.slurp.lc ~~ m:g/ [<[\w] - [_]>]+ /;)».Str.Bag.sort(-*.value)[^$top]
.say for $/».Str.Bag.sort( -*.value )[^$count];
}</lang>
 
10,339

edits