salutations, we have an array with 274947 items (generated from a text file with 274947 lines and 2.235 MB), and we need to find items of this array that match some pattern (or several patterns). basically, each item of the array is a word, in simple text form (so the array would be a word list). we can't use hashes, because, as far as we know, hashes don't have capability of searching for patterns with regexps. we also tried connecting to an Access database, but it gets too slow. here's the best we've got so far:
#!c:/perl/bin/perl print "Content-type: text/html\n\n"; open BAP, "db.txt"; @biff = (); while (<BAP>){ if (/foo/){ push(@biff, $_)}; if (/bar/){ push(@biff, $_)}; if (/baz/){ push(@biff, $_)}; ... } print "@biff"; close BAP;
as you can see, it loops through the db.txt file, adding the lines to @biff when it matches a certain regexp. matching all lines to one single pattern is fairly fast, but matching to many patterns is very slow, because we need to grep several times. we've also tried the approach @biff = grep(/regexp/, @db) (repeating this line for every pattern, or putting all patterns in one regexp separated by the | operator), but it's as slow as the other technique. any suggestion for a faster way of grepping? or maybe even a very different approach other than storing the list in arrays (but still allowing us to search for patterns in a fast way)? salutations,

In reply to parsing a very large array with regexps by pc2

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.