Use of keys, map and sort (untested)
foreach my $subject (sort {lc($a) cmp lc($b)} map {[ $_, $subjects{$_}]}
keys %subjects){
printf "%-40s: %-s\n", $subjects{$subject->[0]}, $subject->[0];
}
Wags ;)
-----Original Message-----
From: David Gilden [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 14, 2001 12:10
To: [EMAIL PROTECTED]
Subject: Sort hash by values
Hello,
Stuck here,
The first sort block works like a charm!
if ($sort_order == 1) {
# sort by name
# $key is really the filename with out the path and '.html'
foreach my $key (sort {lc($a) cmp lc($b)} keys %subjects){
my $name;
($name = $key ) =~ s/_(\d+)$//;
$name =~ tr/_/ /;
&print_table_rows($key,$name,$subjects{$key}," ");
}
}
However, this one has be stuck, I want to sort (case insensitive) the
values
in the hash %subjects, and I need to get keys of the hash as well --
the key of the hash has data I need to pass along to my sub,
elsif ($sort_order == 2) {
# sort by subject
foreach my $subject (sort {lc($a) cmp lc($b)} values %subjects){
##
need the key here...
my $name;
($name = $key ) =~ s/_\d+$//;
$name =~ tr/_/ /;
##
&print_table_rows($key,$name,$subject," ");
}
--------------------------------------------
Looking for Web Talent, You found it!
portfolio: www.coraconnection.com/web/
email: [EMAIL PROTECTED]
tel/fax: (860) 231-9988
--------------------------------------------