Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

(boo) Re: Replacing a given character starting with the xth occurence in a string

by boo_radley (Parson)
on May 21, 2001 at 19:24 UTC ( [id://81990]=note: print w/replies, xml ) Need Help??


in reply to Replacing a given character starting with the xth occurence in a string

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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://81990]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-20 03:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found