in reply to String matching idea

For the 1-to-1 case, just do the obvious thing, there are no shortcuts for that problem.

For the N-to-N case, use a trie or prefix tree.

Replies are listed 'Best First'.
Re^2: String matching idea
by Anonymous Monk on Sep 18, 2015 at 18:32 UTC

    Please indulge my curiosity - what do you consider "the obvious thing" ?

      Oh, well, I meant doing the obvious thing in C (or any other low-level enough language): comparing the characters one by one sequentially until a divergence is found.

      If you limit the solution to Perl, as it doesn't provide some builtin that could do that, we go into the land of tricks, as the solution posted by choroba above.