This might be off base, but it looks like your script is working through a browser input/ form data. If this is so, then the key won't show up if the user doesn't put in an answer for the field, even if you pass that field to your CGI script. In other words if I have a field named "address" and the user doesn't fill in that field then the field address won't be in the parse string.

This function is pretty well known from the O'Riely CGI book (good book to get if you are going to do a lot of this stuff)
sub parse_form_data { local (*FORM_DATA) = @_; local ($request_method, $query_string, @key_value_pairs, $key_value, $key, $value); $request_method = $ENV{'REQUEST_METHOD'}; if ($request_method eq "GET") { $query_string = $ENV{'QUERY_STRING'}; } elsif ($request_method eq "POST") { read (STDIN, $query_string, $ENV{'CONTENT_LENGTH'}); } else { &return_error (500, "Server Error", "Server uses unsupported method"); } @key_value_pairs = split (/&/, $query_string); foreach $key_value (@key_value_pairs) { ($key, $value) = split (/=/, $key_value); $value =~ tr/+/ /; $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg; if (defined($FORM_DATA{$key})) { $FORM_DATA{$key} = join ("\0", $FORM_DATA{$key}, $value); } else { $FORM_DATA{$key} = $value; } } }
Now with that you can write a simple function page like this to see if the variable even exists before using it.
#!/usr/local/bin/perl &parse_form_data (*simple_form); print "Content-type: text/plain", "\n\n"; $address = $simple_form{'address'}; if ($address) { print "Your Address is ", $simple_form{'address'}, ".", "\n"; print "Please visit this Web server again!", "\n"; } else { print "You did not enter a address.", "\n"; print "But, you are welcome to visit this Web server again!", "\n" +; } exit(0);
Don't give me credit for the code, again its paraphrased from the O'Riely CGI book, but as you can see it takes care of the problem on if you got the information or not.

Hope this helps

Glenn H.

In reply to Re: If statements while in PRINT by webadept
in thread If statements while in PRINT by venimfrogtongue

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.