One optimization depends on what $table and the lines in fg_log look like. If you can pre-sort the strings you are looking for into a fixed amount of buckets, you can check the $cur_line for which buckets could possible match it and so avoid matching against all the unsuitable buckets

As an example lets assume that $table always holds 10 digit numbers and each fh_log line consists of text and a few of those 10 digit numbers inbetween.

Then you could put all numbers beginning with 00 into bucket 00, all the numbers beginning with 01 into the bucket 01 and so on. Then you just need to extract the numbers from every line and check them only against the numbers in the suitable bucket.

The same optimization could be done if you always look for whole words, or sequences that always have a '-' inbetween (use the char before and after the '-') and a lot of other situations, you just need some structure in your data you can take advantage of.


In reply to Re: Perl Optimization by jethro
in thread Perl Optimization by Chivalri

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.