Adam has asked for the wisdom of the Perl Monks concerning the following question:
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 )
but Perl didn't like that very much.sub Half { my $n = shift; my $SubBody = Power_Of_Two( $n ) ? "return \$_[$[] >> Log2( $n );" : "return int( \$_[$[] / $n );"; my $SubRef; eval "$SubRef = sub { $SubBody }"; return $SubRef; }
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.)
Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE (tilly) 1: Fly Subroutines on the Fly
by tilly (Archbishop) on Sep 19, 2000 at 06:03 UTC | |
by BlaisePascal (Monk) on Sep 19, 2000 at 06:30 UTC | |
by chromatic (Archbishop) on Sep 19, 2000 at 07:09 UTC | |
by tilly (Archbishop) on Sep 19, 2000 at 15:23 UTC | |
by BlaisePascal (Monk) on Sep 19, 2000 at 22:29 UTC | |
by Adam (Vicar) on Sep 19, 2000 at 22:41 UTC | |
by merlyn (Sage) on Sep 19, 2000 at 22:32 UTC | |
| |
by Adam (Vicar) on Sep 19, 2000 at 19:37 UTC | |
by tilly (Archbishop) on Sep 19, 2000 at 19:49 UTC | |
|
Re: Fly Subroutines on the Fly
by fundflow (Chaplain) on Sep 19, 2000 at 06:28 UTC |