in reply to speeding up a regex
I'd recommend two minor changes --
* I know, that's not specifically true, as with your case, you can match each item in the list once, but I'm making a general assumption that your items look to be SQL statements, and if they're single statements, they're most likely mutually exclusive, so long as you don't have sub queries
I'd probably rewrite it something like:
my $pattern = qr/\b(?:create|drop|delete|update|insert)\b/i; # open a database connection here (using Sybase::DBD) and # create a statement string to execute $sth=$dbh->prepare("@sqlstatement"); $sth->execute; while ($data = $sth->fetchrow_arrayref()) { next if($data->[10] =~ /tempdb/i); if ($date->[13] =~ $pattern) { print "$data->[3] $data->[9] $data->[10] $data->[13]\n"; } }
You can also use perl's foreach loops to deal with iterating through a list, when the actual index isn't important. (yes, I know, it can be called with 'for', but I always think of C's for loops when I use 'for')
|
|---|