Re: s/A/B/ and s/B/C/ but don't want A -> C



_
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;
.