Jim wrote:
>Jim Gibson [jimsgib...@gmail.com]
>      Sent: Thursday, March 22, 2012 1:39 AM
>      To: beginners@perl.org
>
>
>
>
>At 12:26 PM +0800 3/22/12, lina wrote:
>>
>>%abbrev = (
>>             'CNS Neurol Disord Drug Targets' => 'CNSNDDT',
>>             'Intermolecular Forces' => 'IF',
>>             'Expert Reviews in Molecular Medicine.' => 'ERMM',
>>             'Nat. Neurosci.' => 'NN',
>>             'Nat. Rev. Mol. Cell Biol.' => 'NRMCB',
>>             'Nature Cell Biol.' => 'NCB'
>>           );
>>
>>My question is that how can I sort the values. I googled for a while.
>>
>>sort $abbrev{$a} cmp $abbrev{$b} it complains that:
>
>You need to put the sort test in a block:
>
>for my $key ( sort { $abbrev{$a} cmp $abbrev{$b} } keys %abbrev ) {
>   print "key=$key, value=$abbrev{$key}\n";
>}

Since the default sort order, where items are sorted as strings in ASCII 
sequence is not being changed, the following is sufficient:
for my $key (sort keys %abbrev) {
   print "key=$key, value=$abbrev{$key}\n";
}

HTH, David Kronheim

This communication is confidential.  Frontier only sends and receives email on 
the basis of the terms set out at http://www.frontier.com/email_disclaimer.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to