Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: How can I expand my substring?

by choroba (Abbot)
on Jun 30, 2014 at 12:50 UTC ( #1091709=note: print w/ replies, xml ) Need Help??


in reply to How can I expand my substring?

Instead of going the /e way, which is a bit hard to read, I'd remove the offending part from the string, do the replacements, and return it back:

#!/usr/bin/perl use warnings; use strict; use Test::More tests => 4; sub fill { my $_ = shift; my $prefix = do { s/^(-*B?)// ; $1 }; 1 while s/-B/BB/g or s/B-/BB/g; return "$prefix$_" } is(fill('--------NNNNNNN--------NNNNN--------NNNNN------NNNNNNN------- +------BBBBB-----'), '--------NNNNNNN--------NNNNN--------NNNNN------NNNNNNNBBBBBBB +BBBBBBBBBBBBBBBB', 'test1'); is(fill('---------NNNNN-NNNNNNNNNNNNN----NNNNNNNNNNN---------BBBBBBBBB +B'), '---------NNNNN-NNNNNNNNNNNNN----NNNNNNNNNNNBBBBBBBBBBBBBBBBBB +B', 'test2'); is(fill('-------NNNNNNN-----------------BBBBBBBBBBBBBBB-------------NN +NNNNN'), '-------NNNNNNNBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBNN +NNNNN', 'test3'); is(fill('--------BBBBBBBBBBBB-------NNNNNNNNNNNNN------NNNNNN'), '--------BBBBBBBBBBBBBBBBBBBNNNNNNNNNNNNN------NNNNNN', 'test4');
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: How can I expand my substring?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2014-12-28 16:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls