Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Tips on how to perform this substitution?

by tobyink (Abbot)
on Jan 22, 2014 at 14:16 UTC ( #1071618=note: print w/ replies, xml ) Need Help??


in reply to Re: Tips on how to perform this substitution?
in thread Tips on how to perform this substitution?

It can be done in one s/// operation...

use v5.10; use strict; use warnings; $_ = '--BBB----BB--B-------B--B--BBBB---B--'; s ((B+|.)) { state $char = 'i'; if (index($1, 'B') == 0) { $char = $char eq 'i' ? 'o' : 'i'; 'M' x length($1); } else { $char; } }eg; say;
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name


Comment on Re^2: Tips on how to perform this substitution?
Select or Download Code
Re^3: Tips on how to perform this substitution?
by Tux (Monsignor) on Jan 22, 2014 at 14:47 UTC

    That is way too complex :)

    my $p = "--BBB----BB--B-------B--B--BBBB---B--"; my @x = qw( i o ); my $x = 0; $p =~ y/B/M/; $p =~ s/(-+)/$x[$x++%2]x length($1)/ge; say $p;

    Enjoy, Have FUN! H.Merijn

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2014-08-01 10:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (5 votes), past polls