One thing you could do to speed things up is to let SQL do what it is good for. For example, say your $data->[10] row is called 'database'. Then get SQL to remove everything that has 'tempdb' in it with a WHERE database NOT LIKE '%tempdb%'. And also, if your list of keywords to search for are never actually regexes, just a list of keywords, then you can add something like:

WHERE database NOT LIKE '%tempdb%' AND ( keyword LIKE '%create%' OR keyword LIKE '%delete%' OR keyword LIKE '%insert%' ... )
I would achieve that by some code like this probably.
my @patterns = qw/create delete insert update drop/; my $query = "@sqlstatement"; # don't know what you already have in @sq +lstatement though $query .= qq{WHERE database NOT LIKE '%tempdb%'; $query .= qq{AND (}; $query .= join " OR ", map { qq{keyword LIKE '%$_%'} } @patterns; $query .= qq{)}; sth=$dbh->prepare( $query ); $sth->execute; while ($data = $sth->fetchrow_arrayref()) { # the query did all of our checking, so we don't need to check anyt +hing. print "$data->[3] $data->[9] $data->[10] $data->[13]\n"; }

    -Bryan


In reply to Re: speeding up a regex by mrborisguy
in thread speeding up a regex by Anonymous Monk

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.