Re: s/A/B/ and s/B/C/ but don't want A -> C
- From: Ted Zlatanov <tzz@xxxxxxxxxxxx>
- Date: Fri, 28 Dec 2007 14:11:45 -0600
On Fri, 28 Dec 2007 11:52:49 -0800 (PST) nolo contendere <simon.chao@xxxxxxx> wrote:
nc> 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.
nc> Oh yeah, just saw Michele's post. I forgot the capturing parens,
nc> should be:
nc> s/([ABC])/replacement( $1 )/e;
I forgot the parenthesis, but it doesn't change my question. \1 works
like $1 in this case, I used it out of habit.
Look at my example. When you are given a list of "X -> Y"
transformations, you don't know in advance how to order them so they
won't overlap (as in the A to B to C example). You need to look through
the list. The right ordering may not even be possible (if there's a
loop in the graph). That's what I meant by "don't know in advance." By
"complex" I mean that the overlap may not be obvious if the
replacement's output is not a simple function of the input.
Ted
.
- Follow-Ups:
- Re: s/A/B/ and s/B/C/ but don't want A -> C
- From: nolo contendere
- 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
- 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: FAQ 5.33 How do I close a file descriptor by number?
- Next by Date: Re: s/A/B/ and s/B/C/ but don't want A -> C
- 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
|
|