Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Tips on how to perform this substitution?

by TomDLux (Vicar)
on Jan 23, 2014 at 05:21 UTC ( [id://1071695]=note: print w/replies, xml ) Need Help??


in reply to Tips on how to perform this substitution?

Rather than focusing on how to do this in as few characters as possible, consider doing it in a manner that is clear

my $str = '---BBB--- ..... '; my @bits = split /(B+)/, $str;

produces @bits:

0: '---' 1: 'BBB' 2:'---'

processing through @bits, you have to consider the possibility that the first character was a 'B', in which case $bits[0] will be B', in which case you convert to M's, otherwise the first part will convert to the odd pattern. Then a string of Bs, then the even pattern, and so on.

As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2025-07-20 01:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.