My first post here, so please be gentle. I have a very basic CGI script (and I have stripped it out here even more just to illustrate the problem). The problem is thus -- the first time I load the web page (that is, no form is submitted), "template," the first field in the form, automatically gets the value "minscale". If I actually enter something in the "template" and "minscale" fields, the entered values are correctly passed and reflected back in the preformatted output at the bottom of the page. Its just that first time... it seems the hash definition at the top is causing the problem... the "template" key is getting nothing from param('template') and is using the name of the next key as its value. Any advice will be much appreciated. Code follows
#!/usr/bin/perl -w use strict; use CGI::Pretty qw(:standard); use CGI::Carp qw(fatalsToBrowser); my %webobj = ( 'template' => param('template'), 'minscale' => param('minscale') ); print header, start_html; print<<WEBOBJ; <form method='get' action='webobj.cgi'> <b>Web Object</b> <table border='0'> <tr> <td align='right'>Template</td> <td><input type='text' name='template' value="$webobj{'templat +e'}"></td> </tr> <tr> <td align='right'>Minscale</td> <td><input type='text' name='minscale' value="$webobj{'minscal +e'}"></td> </tr> <tr><td></td><td colspan='2'><input type='Submit' value='submit'> +<input type='reset'></td></tr> </table> </form> <pre> # ## start web object WEB TEMPLATE "$webobj{'template'}" MINSCALE $webobj{'minscale'} END # end web object # </pre> WEBOBJ print end_html;

In reply to Puzzling CGI behavior by punkish

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.