Easiest way to do that is just use a hash mapping the whatever.gif|jpg to the text values. You use hashes in your program already so I guess you don't need an explanation of how to use them. :)
Note: untested code follows:
#!/usr/bin/perl -w
require "cgi-lib.pl";
&ReadParse;
my %hashOfAnimals = (
"pets.gif" => "Your Favorite Pet",
"afghanhd.jpg" => "Big dogs",
"austter.jpg" => "Little dogs",
"ragdoll2.jpg" => "Cats",
"fish1.jpg" => "Fresh water fish",
"gerbil.jpg" => "Gerbils",
"morganhorse.jpg" => "Horses",
"parrot.jpg" => "Parrots",
"macaw.jpg" => "Macaws",
"toucan.jpg" => "Toucans",
"snap.jpg" => "Turtles",
"iguana.jpg" => "Iguanas",
"sinaloan.jpg" => "Snakes"
);
#color.cgi
#Warn browser that HTML is coming
print &PrintHeader;
print <<"eohtml";
<html><head><title>Thanks for responding</title></head>
<body bgcolor = "#FFFFFF"><H1>Thank You</H1>
<p>What a coincidence, $in{'firstname'} $in{'lastname'}!!</p>
<p>My favorite color is $in{'color'} <strong>AND</strong> I Love $hash
+OfAnimals{$in{'pet'}}.</p>
</body></html>
eohtml
#End of Program
Updated: Forgot if key has . in it, key needs to be quoted. Doh!
antirice
The first rule of Perl club is - use Perl
The ith rule of Perl club is - follow rule i - 1 for i > 1
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.