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

Re: Tips on how to perform this substitution?

by kcott (Archbishop)
on Jan 22, 2014 at 14:59 UTC ( [id://1071628]=note: print w/replies, xml ) Need Help??


in reply to Tips on how to perform this substitution?

Here's another way to do it:

#!/usr/bin/env perl -l use strict; use warnings; my $string = '---BB--BBB---BBB---B-B---'; print $string; $string =~ y/B/M/; print $string; my @subs = qw{i o}; my $i = 1; $string =~ s/(-+)/$subs[$i ^= 1] x length $1/eg; print $string;

Output:

---BB--BBB---BBB---B-B--- ---MM--MMM---MMM---M-M--- iiiMMooMMMiiiMMMoooMiMooo

-- Ken

Log In?
Username:
Password:

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

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

    No recent polls found