I love all of the answers to this question, especially
ZZamboni's,
satchmet's and
tachyon's.
I went over and said to @coworker, "lookie this!", and they replied "what the hell does that do?"
I explained what the topic was.
$coworker[1] says "ah, that's faboo, but how does it do it?" and it took me about 5 minutes to puzzle through
ZZamboni's. He explained that the idea's useful, but the implementation was a bit opaque for him. We chatted for a few more, and then I suggested the following, which is a much different take.
use strict;
my $s=n_sub ("Toy boats are for the little boys" ,2,"b","g");
$s=n_sub ($s,4,"o","i");
$s=n_sub ($s,2,"y","rl");
print $s;
sub n_sub {
my ($os, $xth, $ic, $oc) = @_;
my @el= split /$ic/,$os, $xth;
$el[-1] =~ s/$ic/$oc/g;
return join ($ic, @el);
}
I don't suggest that this may be a faster implementation, or a better one, but for those that I showed, it's more understandable.
I'm not knocking anyone's reg-fu, of course, but even some basic concepts like
?: confound some, and I wanted to show TIMTOWTDI.
on a related subject, isn't this concept called lookbehind, as in the owl, pg 229 and 230?