Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re: Code Optimization v5.8.1

by mirod (Canon)
on May 20, 2004 at 20:19 UTC ( [id://355065]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-18 23:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found