Created
July 25, 2022 19:24
-
-
Save rram/1151056301915dc53b6cd1bc958472ae to your computer and use it in GitHub Desktop.
Count the frequency of values on standard input
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/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