# hash.p PERL program to illustrate using a hash to keep counts # of the occurrences of characters in the data. my %letterCount; $str = "...ABCABC PANTHERS UNI MAUCKER UNION..."; @a = split(//, $str); foreach (@a) { print "$_ "; if ( exists $letterCount{$_} ) { $letterCount{ $_ }++; } else { $letterCount{ $_ } = 1; } } print "\n\n"; foreach $char (keys %letterCount) { print " $char = $letterCount{ $char } \n"; } ----------------------------------------------------------------------------- OUTPUT - hash.out perl hash.p > hash.out ----------------------------------------------------------------------------- . . . A B C A B C P A N T H E R S U N I M A U C K E R U N I O N . . . = 4 A = 4 B = 2 C = 3 E = 2 H = 1 I = 2 K = 1 M = 1 . = 6 N = 4 O = 1 P = 1 R = 2 S = 1 T = 1 U = 3