Hey Folks! I'm still new here, and new to Perl in general.

Still trying to craft, btw, an online presence here that doesn't annoy too many of us! :) I was thinking of "Perl-21 Lemay p.243 ex 4" (honestly!) but that seemed a little less...catchy? I suppose would be the word. At any rate, if you'd like to holler at me that this would have been a better title, by all means! Fire away! Formatting tips also welcome!

So here's the problem from -duh- "Sams Teach Yourself Perl In 21 Days by Laura Lemay". It's example 4 on page 243.

The problem states:

-------------------------------------------------------

'Write a problem to expand acronyms in its input (for example) to replace the letters "HTML" with "HTML (Hypertext Markup Language)". Use the following acronyms and meanings to replace:

HTML (Hypertext Markup Language)

ICBM (InterContinental Ballistic Missile)

EEPROM (Electrically-erasable programmable read-only memory)

SCUBA (Self-contained underwater breathing aparatus)

FAQ (Frequently Asked Question)'

---------------------------------------------------


I didn't phrase the output in quite the same way, but my answer was close enough in gross concept, IMB. So my question is, no, not for you to write the proggie for me! But rather, I came up with a solution that is a little less than...how shall we say? elegant! I realize that Mike Gancarz according to his "Unix Philosophy" (also new to that!) would disagree with this question, but I would love to know how a vet perl user would approach the problem.

btw, this *works* on my Linux laptop. But unfortunatly I'm visiting with relatives and all they have is dialup! And they don't want me installing all this "hacker stuff" (????!!!!!...and not that they would even likely know it if'n I did!!!) onto their pc. Eh, I'm the guest. Guess I'll just "reinvent the wheel"! Also counter to UNIX ideology, I know. I'm not asking for that kind of help, btw. I plan on visiting an installfest soon. But please try to bear with me! :)

So what I'm trying to say (in my ugly and verbose sort of way...much like my code!) is that this may work, or I may typo in the translation. If so, I accept all criticisms.

Here goes!

---------------------------------------------

#!/usr/bin/perl -w $in = (); # usr input $exit = 'n'; # done yet? $final = (); # final output %acro = (); # hash for acronyms %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", # my own goofy ass + addition. Others welcome! 'NASA' => "National Aeronautical and Space Administration" # ditto ); while () { print "\nPlease enter an acronym": "; chomp($in = <STDIN>); print "\n"; foreach $ac (keys %acro) { if ($in =~ /$ac/ig) { $final = "\n$ac is the acronym for $acro{ac} \n\n"; last; } else { $final = "\nSorry. But that is not an acronym that I recognize!\n" +; } print $final; $final = (); print "\nTry again? : "; chomp ($exit =~ /[y|yes]/i { next; print "\n"; last; } print "\n"; last; } <br><br>
------------------------------------------------------

So there ya have it! Ugly crappy code from a total noob! :) But what the hey, it works!

THANKS!

In reply to 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.