I'm trying to write a program in Perl that will allow me to keep track of recipes. It is my way of practicing my Perl coding and at the same time creating something I could actually use. I've unfortunately run into a problem with the following code:
# if the HTML has not yet been displayed, display it if ($formdata{'mode'} eq "setup") { open (HTML, "<../add_whole_meal.html") || die &show_error("Unable +to open add_meal.html: $!"); unless ($content_type == 1) { print "Content-type: text/html\n\n"; $content_type = 1; } while(<HTML>) { $_ =~ s/\$(\w+)/$formdata{$1}/eg; $_ =~ s/\+_errors_\+//; print; } close(HTML); } elsif ($formdata{'mode'} eq "check") { # first make sure there is at least one item that has been entered if (($formdata{'name1'} eq "") && ($formdata{'name2'} eq "") && ( +$formdata{'name3'} eq "") && ($formdata{'name4'} eq "") && ($formdata +{'name5'} eq "")) { $error_message = $error_message . "<li>You must enter at least + one item </li>"; $flag = 1; } # check to see if a name was given, that all other sections are fi +lled in if (($formdata{'name1'} ne "") && (($formdata{'ingredients1'} eq " +") || ($formdata{'instructions1'} eq ""))) { $error_message = $error_message . "<li>Please be sure all requ +ired parts of item1 are filled in</li>"; $flag = 1; } # removed some of the repetitive code # check to make sure all numbers are actually numbers if (($formdata{'calories'} !~ m/\d*/) || ($formdata{'calories'} !~ + m/\d*/) || ($formdata{'calories'} !~ m/\d*/) || ($formdata{'calories +'} !~ m/\d*/)) { $error_message = $error_message . "<li>Please be sure all of t +he general information is in numeric form</li>"; $flag = 1; } # display error if needed and regenerate form if ($flag == 1) { open (HTML, "<../add_whole_meal.html") || die &show_error("Una +ble to open add_meal.html: $!"); unless ($content_type == 1) { print "Content-type: text/html\n\n"; $content_type = 1; } # setup the error message $error_message = "<font face=verdana color=#333333 size=2><cen +ter><b>Unfortunately there was an error!</b></center></font><ul><font + face=verdana color=red size=1>" . $error_message . "</font></ul>"; + # replace as needed and then reprint HTML while(<HTML>) { $_ =~ s/\$(\w+)/$formdata{$1}/eg; $_ =~ s/\+_errors_\+/$error_message/; print; } close(HTML); } }
Everything compiles. The hash %formdata contains all of the parameters sent to the script through the URL. This part I know is working correctly. The first part, when the program receives action=add_meal and mode=setup works perfectly fine. The script displays all of the necessary HTML, replacing whatever needs to be replaced in the static HTML beforehand. In the second part, I'm attempting to check all of the "necessary" fields and display an error message if things aren't correct. In the case of an error message, the HTML is regenerated with the user's previous information stored in the form fields. The script gets passed all of the tests and even shows the correct error message. The problem, however, is that the HTML doesn't finish being displayed. When I run the script with action=add_meal and mode=check, a small portion of the HTML page is displayed and then the script seems to stall. I hit ESC to stop the script and about half of the HTML page appears, but the rest is left out. Any clue as to why this happening?

Here is some of my sample HTML code, incase this will help:
<!-- Commented out to maintain perlmonks.org page <tr> <td bgcolor="#FFFFFF"><font face="verd +ana" color="#333333" size="1"><b>Name:</b><br> Please choose a name for this +portion of the meal. All names are case sensitive</font></td> <td bgcolor="#FFFFFF"><input type="tex +t" size="35" name="name2" value="$name2"></td> </tr> <tr> <td bgcolor="#FFFFFF"><font face="verd +ana" color="#333333" size="1"><b>Ingredients:</b><br> Please enter the ingredients n +eeded for this portion of the meal. Each ingredient should be sepera +ted by a comma.</font></td> <td bgcolor="#FFFFFF"><input type="tex +t" size="35" name="ingredients2" value="$ingredients2"></td> </tr> <tr> <td bgcolor="#FFFFFF"><font face="verd +ana" color="#333333" size="1"><b>Instructions</b><br> Please enter the cooking instr +uctions for this portion of the meal. Enter the instructions exactly + how you want them to be displayed.</font></td> <td bgcolor="#FFFFFF"><textarea size=" +20" name="instructions2" cols="40" rows="5">$instructions2</textarea> +</td> </tr> <tr> <td bgcolor="#FFFFFF"><font face="verd +ana" color="#333333" size="1"><b>Notes</b><br> Please enter any additional no +tes you have about this portion of the meal. Enter the instructions +exactly how you want them to be displayed. (optional)</font></td> <td bgcolor="#FFFFFF"><textarea size=" +20" name="notes2" cols="40" rows="5">$notes2</textarea></td> </tr> -->
Thanks in advance. -Eric

updated by boo_radley : title change, readmore

In reply to CGI hanging during HTML generation (was : anyone have an answer?) by emilford

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.