#!/usr/bin/perl -w my %hash; #==================================================== sub print_bare { print "\n\n"; print "print \%hash with nothing else (no formatting):\n"; print %hash; print "\n\n"; } sub print_formatted { print "print \%hash with other text:\n"; print "\%hash: " . %hash . "\n\n"; } sub print_sorted { print "print \%hash sorted:\n"; foreach my $key (sort { $hash{$b} cmp $hash{$a} } (keys(%hash))) { print "\$key:$key \$hash{$key}:$hash{$key} \n"; } print "\n\n"; } #==================================================== %hash = (' Charlie and Alice ' => ' can ', ' Fred and Ethyl ' => ' cannot ', ' Ernie and Betty ' => ' do not care ', ' Arnold and Janet ' => ' might '); print_bare; print_sorted; print_formatted; print "\n\n"; %hash = (' Charlie and Alice ' => ' can ', ' Fred and Ethyl ' => ' cannot '); print_bare; print_sorted; print_formatted;