On 3/21/12 Wed Mar 21, 2012 9:53 AM, "lina" <lina.lastn...@gmail.com> scribbled:
> Hi, > > For the following keys, I wish the values to be the abbreviation of them, Can you explain what you mean by "abbreviation". It looks like you are looking for the first letter of each word. Is that true? > > Nat. Neurosci. > Expert Reviews in Molecular Medicine. > Intermolecular Forces > Nature Cell Biol. > CNS Neurol Disord Drug Targets > Nat. Rev. Mol. Cell Biol. > > I came up one, not working though, > > > #!/usr/bin/env perl > > use strict; > use warnings; > use autodie qw(open close); > use 5.012; > > > open my $fh, '<', "try.txt"; > > my %abbrev; > my @abbre; > while(my $line = <$fh>){ > if (/([[:upper:]]).*([A-Z]).*?([A-Z])+?/){ > print $1,$2; > print $3,"\n" if defined $3 ## Here is a mess. I don't know how to handle it Just print $3 and leave out the defined test. The third capture group should always be defined, as otherwise the match would not succeed. > $abbre[]=join '',$1,$2,$3; You have an array element, but you have to specified the index. I think you mean to say: $abbre = join '',$1,$2,$3; but you can use this instead: $abbre = "$1$2$3"; > $abbrev{$line} = $abbre; > } > } You might want to use this to capture the first upper-case letter in each word: my @uppers = ( /\b[A-Z]/g ); my $abbre = join('',@uppers); -- Jim Gibson -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/