Re: s/A/B/ and s/B/C/ but don't want A -> C
- From: Abigail <abigail@xxxxxxxxxx>
- Date: 29 Dec 2007 00:23:55 GMT
_
Ted Zlatanov (tzz@xxxxxxxxxxxx) wrote on VCCXXXII September MCMXCIII in
<URL:news:86r6h6y3uf.fsf@xxxxxxxxxxxx>:
)) On Fri, 28 Dec 2007 20:47:50 +0100 Michele Dondi <bik.mido@xxxxxxxxxxxxx> wrote:
))
)) >> approach anyone can recommend?
))
)) MD> Well, similar to yours, except not necessarily with /e (often a hash
)) MD> is enough):
))
)) MD> s/([ABC])/$replacement{$1}/g;
))
)) That works too, much faster but it can only do static strings. I didn't
)) think of it. Thanks.
With 5.10, you can do it with A and B patterns:
use 5.010;
our $REGMARK;
my %replacement = qw [X B Y C];
$_ = "AABDAAABBE";
s/(*:X)A(?{})|(*:Y)B/$replacement{$REGMARK}/g;
say;
__END__
BCDBCE
Note that the (?{}) is there to prevent a bug from triggering.
Abigail
--
print v74.117.115.116.32, v97.110.111.116.104.101.114.32,
v80.101.114.108.32, v72.97.99.107.101.114.10;
.
- 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
- From: Ted Zlatanov
- 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.8 How can I make a filehandle local to a subroutine? How do I pass filehandles between subroutines? How do I make an array of filehandles?
- Previous by thread: Re: s/A/B/ and s/B/C/ but don't want A -> C
- Next by thread: Re: s/A/B/ and s/B/C/ but don't want A -> C
- Index(es):