Skip to content

Instantly share code, notes, and snippets.

@takdavid
Created December 6, 2016 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takdavid/55eea5d306ba7ce3cc245a8ac954f79a to your computer and use it in GitHub Desktop.
Save takdavid/55eea5d306ba7ce3cc245a8ac954f79a to your computer and use it in GitHub Desktop.
Word count
#!/usr/bin/perl
my @w;
while (<STDIN>) { chomp; while (split /[^-\w]+/) { push @w, lc $_; } }
my $c = {};
while (@w) { $c->{$_} += 1; }
my @k = reverse sort { $c->{$a} <=> $c{$b} } keys %{$c};
while (@k) { print $c->{$k}, $k, "\n"; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment