Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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
Replies are listed 'Best First'.
Re^2: Words in Words
by Lotus1 (Deacon) 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 (Chancellor) 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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2016-05-25 11:24 GMT
Find Nodes?
    Voting Booth?