Skip to content

Instantly share code, notes, and snippets.

@pjlsergeant
Created April 30, 2012 08:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pjlsergeant/2556399 to your computer and use it in GitHub Desktop.
Save pjlsergeant/2556399 to your computer and use it in GitHub Desktop.
Concise map-reduce in Perl
use strict; use warnings;
use List::Util qw(reduce);
use File::Slurp qw(read_file);
# Given a list of filenames, return a hash of each word and the number of times
# it occurs.
sub word_count {
reduce { $a->{$b}++; $a } {},
map { split(/\W+/) }
map { lc read_file $_ } @_;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment