in reply to RE: Selective substitution: not in Perl?
in thread Selective substitution: not in Perl?
That doesn't work, suppose I have the string "abacab" and want to replace the second a with an upper case A. Your regex doesn't match. How about this (untested):
#!/usr/bin/perl -w use strict; my $string = "abacab"; print "$string\n"; my $pattern = "a"; my $better = "A"; my $n=1; my $i=0; $string =~ s/($pattern)/$i == $n ? $better : $1; i++/ge; print "$string\n"
Nuance
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: RE: RE: Selective substitution: not in Perl?
by atl (Pilgrim) on Aug 16, 2000 at 15:27 UTC | |
by merlyn (Sage) on Aug 16, 2000 at 15:33 UTC | |
RE: RE: RE: Selective substitution: not in Perl?
by Anonymous Monk on Aug 17, 2000 at 01:46 UTC |
In Section
Seekers of Perl Wisdom