Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Replace character not inside comments

by Vennis (Pilgrim)
on Sep 05, 2002 at 14:14 UTC ( [id://195378]=note: print w/replies, xml ) Need Help??


in reply to Replace character not inside comments

This seems to work:
$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.=$_; }
Edited: Made an elsif instead of several ifs.
Edited: I got a negative vote, i guess because the lack of comment. I found the question a challenge for myself, but i forgot to share the thoughts. Therefor more comment added.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-23 10:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found