A slightly better, and somewhat more readable, extensable way, to write your
main sub is to use a hash instead of a nested switch. That is, you could write it
as:
my %functions = ( default => \&write_default,
warning => \&write_warning,
confirm => \&write_confirm,
commit => \&write_commit );
However, you would need to modify each sub to take the same
arguments, which isn't that hard (see below). In addition, while your script does not do anything if the action type is unknown beyond print out header and footer (even though you have checked for it at check_param), you should still cover it here, so that your function calling routine can look like:
# This is outside of main, in the 'global' block
my %function = ( # see above );
# The rest is inside of main
$action = ( $function{ $action } ) ? $action : 'default';
# you could also have an 'invalid' block here for an invalid
# parameter
&$function{ $action }
( $script_loc, $email, $name, $warning_msg );
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.