in reply to Replace character not inside comments
Edited: Made an elsif instead of several ifs.$test ="\\AFZ\\BJK \\\*\\AFZ...\*\\"; $span = 0; # Span is a span counter foreach( split(/(\\\*|\*\\)/,$test) ){ # Split on spans keeping the co +mmenttags if($_ eq '\\*'){ # See if its a comment-start $span ++; } elsif($_ eq '*\\'){ # if it's a comment-end $span --; } elsif($span eq 0){ # Only if not in comment $_=~s/\\//igs; } $newtest.=$_; }
|
|---|