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 <tzz@xxxxxxxxxxxx>
- Date: Fri, 28 Dec 2007 12:52:26 -0600
On Thu, 27 Dec 2007 21:35:11 +0000 Ben Morrow <ben@xxxxxxxxxxxx> wrote:
BM> Quoth PerlFAQ Server <brian@xxxxxxxxxxxxxx>:
6.4: I put a regular expression into $/ but it didn't work. What's wrong?
Up to Perl 5.8.0, $/ has to be a string. This may change in 5.10, but
don't get your hopes up. Until then, you can use these examples if you
BM> s/8/10/; s/10/12/;
You want that backwards :)
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?
Thanks
Ted
.
- Follow-Ups:
- 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
- FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong?
- Prev by Date: Re: How Do I Locate a value in a text file and evaluate it and then write out that line based on the value?
- Next by Date: Re: count the number of occurences of each different word of a text
- Previous by thread: Re: 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 (was: FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong?)
- Index(es):
Relevant Pages
|