Create a prefix tree for the dictionary that you're trying to match against. Also, add a data element to each node in the tree to mark whether or not it is a valid terminal position.

Then, for each search instance (i.e., each line in the second input file) search the prefix tree. If you end up on a node in your prefix tree that is also a valid terminal position then you have a match. Creating the prefix tree shall have an amortized linear time; searching the prefix tree for each element in a file is bounded in the worst case as taking n*(k/log(base)) time where n is the number of elements in the file and k is the length of the longest string that you're matching against and where base is the number of children each node has.

This approach has the added benefit that once the prefix tree is created it can be reused later. -- jbs36

In reply to Re: Comparing strings (exact matches) in LARGE numbers FAST by Anonymous Monk
in thread Comparing strings (exact matches) in LARGE numbers FAST by perlSD

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.