We don't bite newbies here... much | |
PerlMonks |
Re^2: Perl substitute with the nth matchby LanX (Saint) |
on Jan 13, 2023 at 13:50 UTC ( [id://11149563]=note: print w/replies, xml ) | Need Help?? |
> > OF COURSE I can do this in a loop. > s/cat/++$i/ge interestingly it's possible to avoid /e in an efficient inside-out (TIMTOW) loop version of m/// say pos($txt) while $txt =~ m/cat/g Now with s/// this kind of works, but isn't efficient because pos will be reset each time
and no, using s///g would do the outer loop only once, tho there might be a way to force a single replace with (?FAIL) ... probably?
Cheers Rolf
In Section
Seekers of Perl Wisdom
|
|