The three most obvious speedups you can attempt are to look for exact matches instead of using a regex to see if the number is in your list; to return immediately you find a match instead of continuing to plough through the rest of the list (this will halve your average lookup time, assuming calls are evenly distributed across the numbers); and to put the list into a hash - using the numbers as keys, the actual values don't matter - and use the exists() function to look your prospective victim up.

If you know that your data mostly consists of long runs of consecutive numbers instead of occasional numbers scattered at random through the number space, then you'll get better results by changing the algorithm to look at number prefixes like I do in Number::Phone::UK. The scripts I use for creating the database that uses are in the tarball on the CPAN.


In reply to Re: Searching text files by DrHyde
in thread Searching text files by SteveS832001

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.