|P is for Practical|
Tips on how to perform this substitution?by Anonymous Monk
|on Jan 22, 2014 at 13:06 UTC||Need Help??|
Anonymous Monk has asked for the
wisdom of the Perl Monks concerning the following question:
so, I am new to Perl and currently trying to play around with some small tasks in order to improve my skills...
I am now learning regular expressions and I am stuck with this issue:
Imagine that you have a line like the following:
and you want to transform it to:
, which, in practical terms means: replace all B's with M's and, as far as the - are concerned, start with i and then alternate between i and o on the two sides of the M parts. The B -> M replacement of course is trivial to do and I could also say that if you find ---- in the beginning of the line, replace them with iiii...But I am not sure how to do the alternation thing!
Can you help me on this a bit?