in reply to Re: Implement uclast with a regex
in thread Implement uclast with a regex

Well, I get it to almost the same speed as the double reverse, but only after some modification:
#!/usr/bin/perl use strict; use warnings; use Benchmark qw /cmpthese/; chomp (our @strings = <DATA>); our (@a, @b, @c, @d); cmpthese -1 => { juerd => '@a = map {scalar reverse ucfirst lc reverse} @strings', davido => '@b = map {my $t = $_; $t =~ s/^(.*)(.)$/\L$1\U$2/; $t} +@strings', dada1 => '@c = map {lc (substr ($_, 0, length ($string) - 1)) . uc (substr ($_, -1, 1))} @strings', dada2 => '@d = map {lc (substr ($_, 0, -1)) . uc (substr ($_, -1, 1))} @strings', }; die 1 unless "@a" eq "@b"; die 2 unless "@a" eq "@c"; die 3 unless "@a" eq "@d"; __DATA__ ACta abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnop +qrstuvwxyz I have a question! yet another way, which should be quickier than the double reverse: Rate davido dada1 dada2 juerd davido 21081/s -- -68% -70% -70% dada1 65511/s 211% -- -6% -7% dada2 69592/s 230% 6% -- -1% juerd 70275/s 233% 7% 1% --

Abigail