Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: Efficient walk/iterate along a string

by GrandFather (Sage)
on Nov 25, 2010 at 00:42 UTC ( #873558=note: print w/replies, xml ) Need Help??


in reply to Re^3: Efficient walk/iterate along a string
in thread Efficient walk/iterate along a string

I'm disappointed at only a 60% improvement! Maybe the segments are shorter than I would have guessed. This technique would give the best improvement for long strings containing few segments.

I used a look behind in the split regular expression to retain the matched character at the end of the previous segment. Use a [KR] match to drop the 'K' or 'R', or use a look ahead match (?=[KR]) to retain the matched character at the start of the segment.

Look behind and look ahead are anchors, they don't "consume" the matched characters, they just mark a position where some match condition is true. In this case we are testing for "was the last character R or K?".

True laziness is hard work

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://873558]
help
Chatterbox?
[marioroy]: why do some posters not know to provide a good SSCCE? Nested loops?
[Corion]: marioroy: Producing good SSCCE is an acquired skill :) You have to produce bad SSCCEs for a long time until you get good. And when you get good, you don't need them that much anymore because you simply isolate the problem and then solve it ;)
[marioroy]: ... and kcott is able to provide something. Amazing.
[hippo]: kcott's analysis consistently impresses.

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2017-08-18 08:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (297 votes). Check out past polls.

    Notices?