Skip to content

Instantly share code, notes, and snippets.

@ovntatar
Created December 16, 2013 15:14
Show Gist options
  • Save ovntatar/7988634 to your computer and use it in GitHub Desktop.
Save ovntatar/7988634 to your computer and use it in GitHub Desktop.
Counting words in a file
#!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