Hi, I have a performance issue to use Perl regular expression to tag protein names in list of sentences. I have 7 million protein names. Each of the 7 million protein names may contain multiple words, and I would like to tag protein names in a sentence which has perfect match in one of the 7 million names.

The protein names are sorted to match the longest protein name first and I store all protein names into one big string separated by delimiter '|'. The code is shown below:

$sortedproteinnamesstring = join '|', reverse sort map { quotemeta } @ +proteinnames; $line =~ s/($sortedproteinnamesstring)/\*\*$1\*\*/ig;
Each sentence is read and put in a variable '$line'. The regular expression on the 2nd line in the code will take from 0.2 sec to 9.5 sec to process each sentence, varies for each sentence. If I have many sentences to tag, it will take many minutes. I would like to know if there is any alternative to speed up the regular expression searching? Thanks for any suggestion!

In reply to Tag protein names in sentences by sinlam

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.