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:
lina
Date:
March 21, 2012 21:26
Subject:
Re: how to constitute some value based on the possible abbrevation
Message ID:
CAG9cJm=4wOOZTbdvPyXiYw_GyBw=a416niS7FWNQHvxFo+7kdA@mail.gmail.com
>
Thanks for all of you.

>
> my %abbrev;
>
> open my $fh, '<', 'try.txt';
>
>
> while(my $line = <$fh>) {
>  chomp $line;
>  my $abbr = join '', $line =~ /[A-Z]/g;
>  $abbrev{$abbr} = $line;

Here I changed it to 	$abbrev{$line} = $abbre;

> }
>
> use Data::Dumper;
> print Data::Dumper->Dump([\%abbrev], ['*abbrev']);
>
> **OUTPUT**
>
> %abbrev = (
>            'CNSNDDT' => 'CNS Neurol Disord Drug Targets',
>            'NCB' => 'Nature Cell Biol.',
>            'IF' => 'Intermolecular Forces',
>            'NRMCB' => 'Nat. Rev. Mol. Cell Biol.',
>            'NN' => 'Nat. Neurosci.',
>            'ERMM' => 'Expert Reviews in Molecular Medicine.'
>          );

OUTPUT:
%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:

name "main::b" used only once: possible typo at try.pl line 24.
Name "main::a" used only once: possible typo at try.pl line 24.
Use of uninitialized value $a in hash element at try.pl line 24,
<$_[...]> line 6.
Use of uninitialized value $b in hash element at try.pl line 24,
<$_[...]> line 6.
Use of uninitialized value in string comparison (cmp) at try.pl line
24, <$_[...]> line 6.
Use of uninitialized value in string comparison (cmp) at try.pl line
24, <$_[...]> line 6.
Use of uninitialized value in concatenation (.) or string at

Thanks again,

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