Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: Calling options via Sub Routinesby dragonchild (Archbishop) |
on Sep 18, 2003 at 20:35 UTC ( [id://292516]=note: print w/replies, xml ) | Need Help?? |
There are a huge number of ways to do this. They all boil down to:
Now, that's a really piss-poor thing, especially if you have more than 5-10 options. So, we can use a dispatch table. This is a preferred method of doing things.
Now, the dispatch table can be in a module, built on-the-fly, or whatever. What's happening here is that we're taking references to subroutines and associating them with strings. So, whenever we see a given string, we can map that to the given subroutine. This is very similar (but more powerful) to funcp's in C/C++. ------ The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6 Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
In Section
Seekers of Perl Wisdom
|
|