Created
April 30, 2012 08:01
-
-
Save pjlsergeant/2556399 to your computer and use it in GitHub Desktop.
Concise map-reduce in Perl
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
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