Created
November 22, 2013 07:42
-
-
Save soren/7596285 to your computer and use it in GitHub Desktop.
A Perl Word Count reducer script. Can be used as a reducer in Hadoop using the Streaming interface. Tested with Java 1.6 and Hadoop 1.0.4.
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
#!/usr/bin/env perl | |
use warnings; | |
use strict; | |
my $current_word = ""; | |
my $current_count = 0; | |
while (<>) { | |
chomp; | |
my ($word, $count) = split /\t/; | |
if ($word eq $current_word) { | |
$current_count += $count; | |
} else { | |
print "$current_word\t$current_count\n" if length($current_word); | |
$current_word = $word; | |
$current_count = $count; | |
} | |
} | |
print "$current_word\t$current_count\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment