[%# Run this through tpage - from Template %] [% debug = 0 %] [% numbers = [ 1, 2, 3, 4, 5, 6 ] -%] [% end = '\)' -%] [% start = '\w+\(' -%] my %functions = (); [% FOR level = numbers -%] $functions{ [% level %] } = sub { my $string = shift; [% IF debug %]my $warn = "running [% level %] on '$string'";[% END %] $string =~ s/[% end %]{[% level %]}$//; $string =~ s/^([% start %]){[% level %]}//; [% IF debug %]warn "$warn to produce '$string'\n\n";[% END %] return $string; }; [% END -%] $functions{-1} = sub { my $string = shift; $string =~ m/\(([^()]+)\)+/; [% IF debug %]warn "running -1 on $string to produce '$1'\n";[% END %] return $1; }; sub get_proparg_evdb { my $string = shift; my $level = shift || return $string; return &{$functions{ $level }}( $string ) || die 'Add universal function here'; } #### # Test the function against another with known good results. for (@data) { my @args = split; my @copy = @args; my $A = get_proparg( @args ); my $B = get_proparg_evdb( @args ); unless ( $A eq $B ) { warn "function wrong for '$args[1]'\n"; warn "A is '$A'\nB is '$B'\n\n"; } warn "array messed up\n" unless join(' ',@copy) eq join(' ',@args); } #### Rate m-elegant ori ori++ evdb m-elegant 1797/s -- -6% -11% -36% ori 1914/s 7% -- -5% -32% ori++ 2016/s 12% 5% -- -28% evdb 2818/s 57% 47% 40% --