in reply to Re^2: How to make these reg exp changes?
in thread How to make these reg exp changes?

exactly what I was looking for... The trick with the hash was just the thing!
Thank you very much!
  • Comment on Re^3: How to make these reg exp changes?

Replies are listed 'Best First'.
Re^4: How to make these reg exp changes?
by ikegami (Patriarch) on Nov 16, 2009 at 00:15 UTC
    Honestly, the hash has nothing to do with the problem.
    $neg{$1}
    is just short for
    ($1 eq 'o' ? 'i' : 'o')
Re^4: How to make these reg exp changes?
by Anonymous Monk on Nov 16, 2009 at 00:23 UTC
    weird?
    $s='III...MMMMMOOOO....MMMIIII'; print $s."\n"; %neg = ( O => "I", I => "O" ); $s=~s/([IO])(M*)(\.+)/ $1.$2.( $neg{$1} x length($3) ) /eg; $s=~s/(\.+)(?=M*([IO]))/ $neg{$2} x length($1) /eg; print $s;print "\n"; <code> It prints:<br> <code> III...MMMMMOOOO....MMMIIII IIIOOOMMMMMOOOOIIIIMMMIIII

      You told us that if the "." is not the first character, one should look back. Are you saying that's wrong?

      If you actually want to look to the other side of the adjacent Ms,

      perl -wle' my %neg = ( O => "I", I => "O" ); $_ = "III...MMMMMOOOO....MMMIIII"; print; s/([IO])(M+)(\.+)/ $1.$2.( $neg{$1} x length($3) ) /eg; s/(\.+)(?=M+([IO]))/ $neg{$2} x length($1) /eg; print; '