develooper Front page | perl.beginners | Postings from March 2012

RE: how to constitute some value based on the possible abbrevation

Thread Previous | Thread Next
From:
Kronheim, David
Date:
March 23, 2012 01:40
Subject:
RE: how to constitute some value based on the possible abbrevation
Message ID:
F25B3888E10C0F40B1AFEB8E63A27AB10827BC65C4@ROCH-EXCH1.corp.pvt
Jim wrote:
>Jim Gibson [jimsgibson@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.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About