I'm back with another question on my pilgrimage to Perl wizardry.

I have several forms and pages within a site that are all processed by one larger-sized script and rendered by HTML::Template. The user's choices come from the name and value of the various submit buttons throughout the site. Example:
<input type="submit" name="funct" value="View Books">
or by some hard links, like:
<a href="cgi-bin/script.pl?funct=view%20books>View Books</a>
CGI parses the input values, including $funct, which then directs the processing to one of a number of subroutines.
SWITCH: for ($funct){ /save news/i && do { &savenews; last; }; /save book/i && do { &addbook; last; }; /save observ/i && do { &addobserv; last; }; /save rule/i && do { &addrule; last; }; /update book/i && do { &updatebook; last; }; /update observ/i && do { &updateobserv; last; }; /update rule/i && do { &updaterule; last; }; /edit news/i && do { &editnews; last; }; /edit book/i && do { &editbook; last; }; /edit observ/i && do { &editobserv; last; }; /edit rule/i && do { &editrule; last; }; /add book/i && do { &addbkform; last; }; /add observ/i && do { &addobform; last; }; /add rule/i && do { &addruform; last; }; /list authors/i && do { &listall; last; }; /list titles/i && do { &listall; last; }; /view news/i && do { &viewnews; last; }; /view book/i && do { &viewbooks; last; }; /view observ/i && do { &viewobserv; last; }; /view rule/i && do { &viewrules; last; }; /next/i && do { &viewbooks; last; }; /prev/i && do { &viewbooks; last; }; $funct = ""; } print "Content-type: text/html\n\n"; print $template->output; #display html #end
I left all that "switching" code in there so you could see just how many subs need to be called and how they are called.

Question: (finally!): Is this how, or is this the best way to take a user's selection and direct the processing within the script (assuming one subscribes to the "put-it-all-in-one-script" philosophy)? Is it efficient or a is there a better way? As a web guy I do LOTS of this kind of thing, so I'd like to nip it in the bud.

Thanks!

—Brad
"A little yeast leavens the whole dough."

In reply to Redirection within a Perl script by bradcathey

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.