Ouch.

How many prefixes of each length, though? If you have many of a given length, maybe you could do something like this (writing support code to generate this HOH, of course):

my %prefixList=( 3 => {DEF=>1, SRC=>1}, 6 => {ABCD12=>1}, 10 => {DEEEE11223}, ); #.... # inside the loop foreach my $length(%prefixList) { if($prefixList{$length}->{substr($fields[7],0,$length)}){ ### code here last; } }
If the set of sizes isn't dynamic, you could make that an AOH, with some possibly empty hashes, I guess... You could also get rid of the loop and inline the check for each length, but I don't think that would save you much.

If you're only ever going to have 1 or 2 prefixes of a given length, then this isn't worth it. But given your initial description, I think with a LOT of prefixes and very few different lengths, this could start to pull ahead of the regex.
--
Mike


In reply to Re^5: Bulk Regex? by RMGir
in thread Bulk Regex? by meetraz

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.