I believe I have addressed your concerns with this:
[%# 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'; }

I also wrote the following test code which should check that the function is behaving as it should:

# 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); }

I took into account the uselessness of \o (thank you diotalevi) and also removed the case == -1 check by creating a function for it. Interestingly the results are now even better:

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% --

If I have misunderstood your critique please let me know. As you can see you can set debug = 1 in the template stuff to enable messages during the run that shows that all cases are being used.

--tidiness is the memory loss of environmental mnemonics


In reply to Re: Re: Re: Re: Re: Re: Peeling the Peelings by EvdB
in thread Peeling the Peelings by PetaMem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.