#!/usr/bin/perl -w # This is a simple script to count the number of distinct entries sent it. use strict; my $VERSION=0.1; my %hash = (); while (<>) { chomp; if ( exists $hash{$_} ){ $hash{$_} = $hash{$_} + 1; } else { $hash{$_} = 1; }; if ( scalar keys ( %hash ) > 5000000 ){ die "The number of distinct entries is too large."; } } print STDERR "distinct-keys, occurances\n"; for my $key ( sort keys %hash ){ print STDOUT "$key,$hash{$key}\n"; } =head1 NAME distinct =head1 DESCRIPTION Prints to STDOUT a sorted list of items followed by a comma then followed by the number of instances of that item. In fairness it is only a wrapped implementation of a counter using a simple hash. =head1 README Prints to STDOUT a sorted list of items followed by a comma then followed by the number of instances of that item. In fairness it is only a wrapped implementation of a counter using a simple hash. Take this file C as an example: =over 8 =item C =item C =item C =item C =item C =item C =back If you were to C you should see: =over 8 =item C =item C =item C =item C =back =head1 PREREQUISITES This script requires the C module. =head1 COREQUISITES none =pod OSNAMES any =pod SCRIPT CATEGORIES UNIX/System_administration =cut