Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: mplement uclast with a regex

by Abigail-II (Bishop)
on Mar 10, 2004 at 10:12 UTC ( [id://335404]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://335404]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-24 23:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found