in reply to Re: ucfirst(uclast(lc($user))) ?
in thread ucfirst(uclast(lc($user))) ?

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.


Replies are listed 'Best First'.
Re: Re: Re: ucfirst(uclast(lc($user))) ?
by theguvnor (Chaplain) on Mar 10, 2002 at 21:57 UTC

    Sweet - I have now become a subroutine! And I'm reasonably fast!! :) Kanji++

    ..Guv