intranetman has asked for the wisdom of the Perl Monks concerning the following question:

I have a form that deletes and adds to a reservation calendar. The add works fine. After each addition an updated list of appointments is displayed. However, on deletion the page goes blank. And you have to close and reopen to get the results. Fortunately delete is working, just no refresh:
$cur = CGI->new(); $mode = "default"; if($cur->param("mode")) { $mode = $cur->param("mode"); } $content .= print_form(); if (($cur->param("delete")) { $content .= delete_appointment(); } if($cur->param("laptop")){ $content .= update_day(); } $content .= display_appointments(); open (TEMPLATE, "../template.shtml")||dienice("Content-type: text/html +\n\nCould not find template"); while (<TEMPLATE>){ $page .= $_; } $page =~ s/<!-- ?content ?-->/$content/ig; close (TEMPLATE); print "Content-type: text/html\n\n$page";
You would think it would display the contents after a deletion since it displays after an addition. print_form() returns the form to be filled out, delete_appointments handles removal from the db and does not return anyting, updatE_day adds to database and returns error if any, and display returns the list of reservations.

I think my error is that the script stops executing after a delete since it thinks its done and doesn't run back through. How would I go about refreshing it then so the appointments/reservations display with each deletion?

Replies are listed 'Best First'.
Re: No update after delete
by eibwen (Friar) on May 02, 2005 at 07:06 UTC

    You may be interested in use strict; and use warnings; for development, but be sure to at least turn off warnings for production.

    As to your question of how the query string affects the page display, your code is difficult to follow -- at least trying to reconcile what it appears to do, with what you say it does/should. While I cannot speculate as to your intent, you may be interested in the following:

    Actually, you may have answered your own question:

    print_form() returns the form to be filled out, delete_appointments handles removal from the db and does not return anyting, updatE_day adds to database and returns error if any, and display returns the list of reservations.

    The problem appears to lie in the subs themselves. I'd recommend making a new sub display_reservations with code from sub update_day, and invoked from both sub update_day and sub delete_appointments. Please post the code for the subs if you require further assistance.

Re: No update after delete
by mpeters (Chaplain) on May 02, 2005 at 13:57 UTC
    It is very common to have a switch statement or dispatch style cgi script based on some query param ('mode' in your case). To make life easier, this is exactly what CGI::Application does. While this doesn't directly fix your current code, it would make it a lot easier to understand and maintain since it provides a cleaner execution path.