Just as you do not want a variable to contain the
arbitrary name of a variable that you reference, you do not want a variable to contain the
arbitrary name of a function that you call. Dispatch-tables, by any other name, are a fine solution ... so are
if..elsif blocks.
Throw an exception at a well-defined point if you are given a name that you are not somehow explicitly-prepared to recognize, because this is the only way that you will find that
bug. Another technique that I like to use is to specify that the variable must be the name of an
object of a specified class or parent-class, which contains a
method that I will call. The invoking routine verifies that the object exists, and that it is of the proper class, and wraps the method-call in an exception handler. (This strategy provides context, contained in the object-instance.) You can do this sort of thing in many programming languages and it works everywhere.
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.