Any help, guidance or enlightement that may be offered will be greatly appreciated.

First, where is the $fa in   if ($m =~ /$fa/g){ coming from? The shape of the code suggests that you may have meant to use $f, instead. (If you note already using strict, please consider doing so. It saves a lot of minor typo grief.)

For faster access to the file, your OS may provide some exploitable capabilities. If you're running on a *nix system that includes shared memory, you can slurp the file into shared memory. I might be marginally faster to access it from there, since you can bypass the overhead of openning the file.

As your file grows, linear scans get more expensive. The typical way around this is index the file so that you don't need to read the entire thing to find the pieces you're looking for. Unfortunately, by using regexs to score hits, you make indexing difficult.

Is   if ($s =~ /$d/g){ really how need want to work that comparison? Depending on your data, it could give you a lot of false hits. If the intent is to match a search term $s if it is a word in $d, then   if ( $s =~ /\b$d\b/i ) { is more accurate. That also puts you in a better position to build a search index from the individual words in $d.


In reply to Re: Faster Flat File by dws
in thread Faster Flat File by Buzz

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.