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:
Jim Gibson
Date:
March 21, 2012 22:39
Subject:
Re: how to constitute some value based on the possible abbrevation
Message ID:
p06240800cb906af628d6@[192.168.1.3]
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";
}



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