I think the second example should be:
foreach(sort {$hash{$a} cmp $hash{$b}} keys %hash){
do something...
}
Notice the %hash (and not $hash) at the end.
-----Original Message-----
From: Timothy Johnson [mailto:tjohnson@;sandisk.com]
Sent: Wednesday, November 06, 2002 17:07
To: 'Kurtis'; [EMAIL PROTECTED]
Subject: RE: Hash Sorting?
You can use the longer form of sort for this. You may have seen this
before:
my @array = sort {$a cmp $b} @unsorted;
#$a and $b are default variables for the sort command.
#to reverse sort, you can reverse $a and $b.
You can also do this:
foreach(sort {$hash{$a} cmp $hash{$b}} keys $hash){
do something...
}
which I think is what you want.
-----Original Message-----
From: Kurtis [mailto:kurtis@;asdal.net]
Sent: Wednesday, November 06, 2002 3:01 PM
To: [EMAIL PROTECTED]
Subject: Hash Sorting?
Hello all......
Does anyone know how to sort a hash in ascending order on the value?
If possible, a little example!
Thanks,
Kurtis
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]