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.
In reply to Fly Subroutines on the Fly by Adam
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |