in reply to Re^2: find acronyms in a text
in thread find acronyms in a text

Thanks a lot, but I don't understand the line  my @words = $_ =~ m/\b[A-Z]+\b/g;

I used regular expressions here to capture all consecutively appearing upper case alphabets separated by word boundaries (\b). Please check the perl regular expressions documentation

You don't use split ?

You could use split if you like but i think it is better to split by \W+ (non-word character) rather than \s+. This helps keep pattern matching simple in the next step. For the sample text below, using \s+ instead of \W+ would find none unless we perform a more complicated pattern matching later.

my %acronyms; my $text= "An important class of transcription factors called general +transcription factors (GTF) are necessary for transcription to occur. + The Most common GTF's are TFIIA, TFIIB, and TFIIE.And a few more not + mentioned here."; my @words = split('\W+', $text); foreach(@words) { if($_ =~ m/^[A-Z]+$/){ $acronyms{$_}++; } } foreach( keys(%acronyms) ){ print "$_ seen $acronyms{$_} times\n"; }