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?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.