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.