... probably through a hash ...

Yep, you've got it. Here's one way to go about it. The following snippet assumes that the action to act upon is passed via the 'q' parameter (ie: index.pl?q=members):

#!/usr/bin/perl -w use strict; use CGI qw/:standard/; sub main { print header(), start_html('Welcome'), p( strong('Welcome to my website!') ), end_html(); } sub login { print header(), start_html('Member Login'), p( strong('Member Login') ), p('Login below:'), end_html(); } sub members { print header(), start_html('I am a member-only page!'), p( strong('Members Page') ), end_html(); } sub _invalid { print header(), start_html('Invalid Function'), p( strong('Invalid Script Function') ), p('That fucntion is not valid!'), end_html(); } my $actions = { main => \&main, login => \&login, members => \&members, _invalid => \&_invalid }; my $q = param('q') || 'main'; $actions->{ exists $actions->{$q} ? $q : '_invalid' }->();


If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, please reply to this node or /msg me to inform me as to what is wrong with the post, so that I may update the node to the best of my ability.


In reply to Re: Event Handling in CGI by Coruscate
in thread Event Handling in CGI by Tanalis

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.