http://www.perlmonks.org?node_id=189269


in reply to Building an anonymous subroutine

How about:
sub template { my $e = shift; my $not_common_a = $e eq 'b' ? sub { ... } : $e eq 'u' ? sub { ... } : sub { ... } ; my $not_common_b = $e eq 'x' ? sub { ... } : sub { ... } ; return sub { $common_stuff; $not_common_a->(); $more_common_stuff; $not_common_b->(); } }
____________
Makeshifts last the longest.