Re: s/A/B/ and s/B/C/ but don't want A -> C (was: FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong?)
- From: nolo contendere <simon.chao@xxxxxxx>
- Date: Fri, 28 Dec 2007 11:52:49 -0800 (PST)
On Dec 28, 2:51 pm, nolo contendere <simon.c...@xxxxxxx> wrote:
On Dec 28, 1:52 pm, Ted Zlatanov <t...@xxxxxxxxxxxx> wrote:
Actually, I've often run into the need for parallel edits like this,
where you want to s/A/B/ and s/B/C but you don't want A to become C.
With complex operations or operations you don't know in advance, proper
ordering becomes impossible. I usually handle it with function calls:
s/[ABC]/replacement(\1)/e or something like that. Is there a better
approach anyone can recommend?
What does the above do? Shouldn't that be:
s/[ABC]/replacement( $1 )/e;
?
And could you please expound on "With complex operations or operations
you don't know in advance..."?
I don't see how you could avoid doing an inadvertent A->C if you did
multiple s/// out of order, unless you provided enough context for the
regex to work correctly.
Oh yeah, just saw Michele's post. I forgot the capturing parens,
should be:
s/([ABC])/replacement( $1 )/e;
.
- Follow-Ups:
- Re: s/A/B/ and s/B/C/ but don't want A -> C
- From: Ted Zlatanov
- Re: s/A/B/ and s/B/C/ but don't want A -> C
- References:
- FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong?
- From: PerlFAQ Server
- Re: FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong?
- From: Ben Morrow
- s/A/B/ and s/B/C/ but don't want A -> C (was: FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong?)
- From: Ted Zlatanov
- Re: s/A/B/ and s/B/C/ but don't want A -> C (was: FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong?)
- From: nolo contendere
- FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong?
- Prev by Date: Re: s/A/B/ and s/B/C/ but don't want A -> C (was: FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong?)
- Next by Date: FAQ 5.33 How do I close a file descriptor by number?
- Previous by thread: Re: s/A/B/ and s/B/C/ but don't want A -> C (was: FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong?)
- Next by thread: Re: s/A/B/ and s/B/C/ but don't want A -> C
- Index(es):
Relevant Pages
|
|