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

Re: Words in Words

by chrestomanci (Priest)
on Sep 30, 2011 at 20:23 UTC ( #928908=note: print w/ replies, xml ) Need Help??


in reply to Words in Words

Instead of using regular expresson to check if one word is a substring of another, why not use index instead.

It is a simple function that returns the offset of the shorter string within the longer one if it is a substring, or -1 it it is not. The kind of thing you expect to find in the string libaries of programing languages without regular expresson support, but so rarely used by perl programmers that most of us have forgotten the function exists.


Comment on Re: Words in Words
Re^2: Words in Words
by Lotus1 (Chaplain) on Sep 30, 2011 at 20:44 UTC

    is index faster than regexp for fixed text token? makes it look like index doesn't help much but I just took a quick look at that long discussion. My guess is the comparison with -1 after every index eats up any savings in search time. Plus the regex looks simpler. (update: simpler to Perl programmers anyway ;)

Re^2: Words in Words
by LanX (Canon) on Oct 01, 2011 at 09:22 UTC
    index is normally slower then a simple regex, because regex are optimized by pre-calculating jump tables ... ( I forgot the name of the algorithm ...).

    Cheers Rolf

    UPDATE: see Boyer–Moore_string_search_algorithm

    UPDATE2: choroba found it, too! :)

      Something like Boyer-Moore?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-10-25 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (143 votes), past polls