Here's a snippet of my code
This extracts an audit trail from a sybase database and examines each row via the regex above. It produces the output I want but I can't help feeling there's a more efficient way of doing the regex bit.my @patterns = ( qr/\bcreate\b/, qr/\bdrop\b/, qr/\bdelete\b/, qr/\bupdate\b/, qr/\binsert\b/, ); 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); for ($loop_index = 0; $loop_index < $#patterns; $loop_index++) { if($data->[13] =~ /$patterns[$loop_index]/i) { print "$data->[3] + $data->[9] $data->[10] $data->[13]\n"; } } }
The first question is , if I wanted to get the keywords from a file (so I can build up a dictionary of keywords to search for) instead of hardcoding them as complied regular expressions as in the code above , how would I do this ? e.g. assume my keyword input file would look like this
create delete insert update drop
Is there a more efficient way of doing the regex ?... I read somewhere about the possibility of using the study function to improve the performance.
Any help appreciated, thanks in advance
In reply to speeding up a regex by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |