|XP is just a number|
Fly Subroutines on the Flyby Adam (Vicar)
|on Sep 19, 2000 at 04:18 UTC||Need Help??|
Adam has asked for the wisdom of the Perl Monks concerning the following question:
What I want to do is write a subroutine that returns an optimized sub-routine.
I started with a closure that returns a subroutine based on the inputs, but now I want to make the resultant subroutine optimized. This means taking different routes to achieve my goal depending on the inputs. ( For example, I don't want to divide by 2**n, but just right shift >>n instead, when a user input is a power of 2 )
I'm not sure how to do this using a closure (short of a big ugly if-then-else structure) so I tried to create subroutines like this:
but Perl didn't like that very much.
Then I was thinking I could do this as a module and imitate however CGI.pm does it, which involves something Dr. Stein called the _make_tag_func and the DefaultClass. I wasn't quite able to follow the good Doctor's code further then that. So much for imitating it.
So I turn to the Monastery and the Monks who dwell within. I wasn't overly concerned with making this sub-routine exceedingly efficient, so much as I was concerned about maintainability and clarity. I was much more concerned with resultant subroutine being efficient (hence all this optimiziation stuff... other wise my closure worked fine.)