Skip to content

Instantly share code, notes, and snippets.

@rram
Created July 25, 2022 19:24
Show Gist options
  • Save rram/1151056301915dc53b6cd1bc958472ae to your computer and use it in GitHub Desktop.
Save rram/1151056301915dc53b6cd1bc958472ae to your computer and use it in GitHub Desktop.
Count the frequency of values on standard input
#!/usr/bin/perl -w
my %buckets;
while(<>) {
chomp;
unless (defined $buckets{$_}) {
$buckets{$_} = 1;
} else {
$buckets{$_}++;
}
}
while(($key, $val) = each(%buckets)) {
printf "%5d %s\n",$val,$key;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment