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

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.

Replies are listed 'Best First'.
Re^2: Words in Words
by Lotus1 (Curate) 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 (Bishop) 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://928908]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2017-12-14 01:13 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (382 votes). Check out past polls.