Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^4: Can you write a faster code to perform this task?

by Lotus1 (Vicar)
on Sep 29, 2014 at 18:30 UTC ( [id://1102376]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Can you write a faster code to perform this task?
in thread Can you write a faster code to perform this task?

I tried it with replacing 'M' with 'M' and it worked. No need to worry about exotic characters.

use 5.014; say 'iiiiiiiiMMMMMMMMMMMooooooooooooMMMMMMMMMMiiiiiMMMMMMMMoooo' =~ tr/M/M/sr=~tr/M//; # => prints: 3

Replies are listed 'Best First'.
Re^5: Can you write a faster code to perform this task?
by BrowserUk (Patriarch) on Sep 29, 2014 at 19:38 UTC

    No need for a new perl and the /r option either. This works fine:

    #! perl -slw use strict; use Time::HiRes qw[ time ]; my $start = time; my $count=0; while( <DATA> ) { # $count += ()= m{M+}g; tr/M/M/s; $count += tr/M/M/; } print $count."\n"; printf "Took %9f secs\n", time() - $start;

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-24 11:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found