Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Words in Words

by chrestomanci (Priest)
on Sep 30, 2011 at 20:23 UTC ( [id://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 (Vicar) 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 (Saint) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://928908]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found