Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: find acronyms in a text

by arun_kom (Monk)
on Jul 23, 2009 at 22:32 UTC ( [id://782804]=note: print w/replies, xml ) Need Help??


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"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://782804]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-19 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found