Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: speeding up a regex
by Aristotle (Chancellor) on Jan 03, 2006 at 15:09 UTC | |
by Anonymous Monk on Jan 03, 2006 at 15:25 UTC | |
by ikegami (Patriarch) on Jan 03, 2006 at 15:44 UTC | |
by sgifford (Prior) on Jan 03, 2006 at 19:59 UTC | |
by ikegami (Patriarch) on Jan 03, 2006 at 21:07 UTC | |
by halley (Prior) on Jan 03, 2006 at 17:03 UTC | |
by Aristotle (Chancellor) on Jan 03, 2006 at 15:52 UTC | |
by Perl Mouse (Chaplain) on Jan 03, 2006 at 16:04 UTC | |
|
Re: speeding up a regex
by ides (Deacon) on Jan 03, 2006 at 15:16 UTC | |
|
Re: speeding up a regex
by kwaping (Priest) on Jan 03, 2006 at 16:02 UTC | |
by Fletch (Bishop) on Jan 03, 2006 at 18:34 UTC | |
by nothingmuch (Priest) on Jan 04, 2006 at 01:53 UTC | |
|
Re: speeding up a regex
by mrborisguy (Hermit) on Jan 03, 2006 at 16:29 UTC | |
|
Re: speeding up a regex
by jhourcle (Prior) on Jan 03, 2006 at 15:40 UTC | |
|
Re: speeding up a regex
by sgifford (Prior) on Jan 03, 2006 at 19:48 UTC | |
by GrandFather (Saint) on Jan 03, 2006 at 22:17 UTC | |
|
Re: speeding up a regex
by Perl Mouse (Chaplain) on Jan 03, 2006 at 15:45 UTC | |
|
Re: speeding up a regex
by Anonymous Monk on Jan 04, 2006 at 10:42 UTC |