carric has asked for the wisdom of the Perl Monks concerning the following question:
So.. if I have two strings I'm searching for, I want it to replace with the the other string; IOW, if I find "nse", I want to replace with "nce" and visa versa.. Every thing I think of seems more complicated than:if(/nce|nse/) { s/$&/replace with what it's not/i; print; }
If that's the only way to do it, sobeit.. but I'm thinking there has to be a more elegant way to tell it to replace with b if it finds a, or a if it finds b.if(nse) { s/nse/nce/i; print; } if(nce) { s/nce/nse/i; print; }
Edit by thelenm: added code tags
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Search and replace logic
by Roger (Parson) on Nov 19, 2003 at 03:44 UTC | |
by carric (Beadle) on Nov 19, 2003 at 07:42 UTC | |
Re: Search and replace logic
by !1 (Hermit) on Nov 19, 2003 at 03:44 UTC | |
Re: Search and replace logic
by ysth (Canon) on Nov 19, 2003 at 03:46 UTC | |
by freddo411 (Chaplain) on Nov 19, 2003 at 17:22 UTC | |
Re: Search and replace logic
by cleverett (Friar) on Nov 19, 2003 at 03:45 UTC |