in reply to Re: Code Optimization v5.8.1
in thread Code Optimization v5.8.1
In this case I often use an alternate method, especially if there are lots of accronyms in the list: I scan the text for things that look like accronyms, and see if they exist in the hash:
#!/usr/bin/perl -w use strict; my %acro = ( HTML => "Hypertext Markup Language", ICBM => "Intercontinental Ballistic Missile", EEPROM => "Electronically-erasable programmable read only memory", SCUBA => "Self Contained Underwater Breathing Aparatus", FAQ => "Frequently Asked Questions", LCARS => "Library Computer And Retrieval System", NASA => "National Aeronautical and Space Administration", ); my $text=<<TEXT; Here is a text that includes LOTS of accronyms like HTML, ICBM, SCUBA etc. Maybe this should be a FAQ. TEXT # substitute all accronymns in the text $text=~ s{([A-Z0-9]+)} # find all upper-case words (st +ored in $1) { $acro{$1} # is it in %acro? ? "$1 ($acro{$1})" # yes, expand it : $1 # no, leave it as is }gex; # g means to do it as many time +s as possible # e means to execute the code i +n the replacement part # x allows multi-line regexp an +d comments print $text;
Note that if accronyms can include lower case letters, you will need to change the matching regexp to include them.
|
|---|