Deciding symbolically which subroutine to call is not a robust implementation. You may be setting yourself (or someone else) up for difficult maintenance issues in the future.
That's because you need to guarantee that
$var1 and
$var2 are always what you expect. Otherwise, as pointed out by
TGI, you
die "A horrible death";
If you
are able to guarantee
$var1 and
$var2, you'd be doing a dispatch table. But then, dispatch tables are not that easy to maintain. Who knows, you may require
$var3 in the future?
Notice how the keys of the dispatch table can be brought in as arguments for a generic function
subby($var1, $var2, ...) that takes both variables as first arguments? The dispatch table is explicitly recreating the pass-arguments-to-subroutine functionality of the language.
If the main reason you're calling subs based on variables is just to refactor code, there's got to be a better way.
If you have time, please consider an alternative implementation. Just my 2 cents.
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.