in reply to Frequency of words in text file and hashes
assuming that case doesn't matter and words are defined by </code>\w+</code>, this code should work:
(notice the extra sort for equal ranking words)my %count; while ( <FILE> ) { $count{lc $_}++ for /\w+/g; } print "$_ => $count{$_}\n" for sort { $count{$b} <=> $count{$a} || $a cmp $b} keys %count;
HTH,
Paul
|
|---|