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.


In reply to Re: Re: Code Optimization v5.8.1 by mirod
in thread Code Optimization v5.8.1 by bluethundr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.