Created
December 16, 2013 15:14
-
-
Save ovntatar/7988634 to your computer and use it in GitHub Desktop.
Counting words in a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!perl | |
# perl script.pl < file.txt | |
use warnings; | |
use strict; | |
my %seen=(); | |
while(<>) { | |
while (/(\w[\w'-]*)/g){ | |
$seen{lc $1}++; | |
} | |
} | |
foreach my $word ( sort { $seen{$b} <=> $seen{$a} } keys %seen) { | |
printf "%d %s\n", $seen{$word}, $word; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment