While it may be the least readable solution of the bunch (IMHO, thanks to the parens; YMMV... ), adapted to work as a uclast function, it's the speediest of the bunch ...

# Output reformatted for readability :) Benchmark: running juerd, seattlejohn, theguvnor, each for at least 5 CPU seconds... juerd: 6 wallclock secs ( 5.18 usr + 0.00 sys = 5.18 CPU) @ 20926.21/s (n=108335) seattlejohn: 6 wallclock secs ( 5.36 usr + 0.00 sys = 5.36 CPU) @ 47568.95/s (n=254922) theguvnor: 5 wallclock secs ( 5.33 usr + 0.00 sys = 5.33 CPU) @ 103021.21/s (n=548897) Rate juerd seattlejohn theguvnor juerd 20926/s -- -56% -80% seattlejohn 47569/s 127% -- -54% theguvnor 103021/s 392% 117% --

With my test script being ...

#!perl use strict; use warnings; use Benchmark qw/ cmpthese /; my $s = "the quick brown fox\njumps over"; sub juerd { my ($foo) = @_; $foo =~ s/(.)$/uc $1/e; return $foo; } sub theguvnor { my ($foo) = @_; $foo = reverse ucfirst reverse $foo; return $foo; } sub seattlejohn { my($foo) = @_; substr( $foo, -1, 1 ) =~ tr/a-z/A-Z/; return $foo; } cmpthese( shift || -5, { 'juerd' => sub { juerd($s) }, 'theguvnor' => sub { theguvnor($s) }, 'seattlejohn' => sub { seattlejohn($s) }, });

    --k.



In reply to Re: Re: ucfirst(uclast(lc($user))) ? by Kanji
in thread ucfirst(uclast(lc($user))) ? by nop

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.