KMR
wc.reduce.pl
1 #!/usr/bin/perl
2 
3 # wc.reduce.pl. Example for KMR shell command pipeline. It is a
4 # reducer for word count.
5 
6 use strict;
7 
8 my $counter;
9 
10 while(<>) {
11  chomp $_;
12  my ($key, $value) = split " ";
13  $counter->{$key} += $value;
14 }
15 
16 for (sort { $counter->{$a} <=> $counter->{$b} } keys %$counter) {
17  print $_, " ", $counter->{$_}, "\n";
18 }