if (index($data,$id)+1){
UPDATE:Ovid's and RMGir's soutions are much more scalable. My suggestion is more of use index instead of regexes.
Benchmark
Benchmark: timing 10000 iterations of index, regex... index: 3 wallclock secs ( 3.52 usr + 0.00 sys = 3.52 CPU) @ 28 +40.91/s (n=10000) regex: 92 wallclock secs (91.44 usr + 0.00 sys = 91.44 CPU) @ 10 +9.36/s (n=10000)
Code for benchmark
sub regex { foreach my $data (@db) { foreach my $id (@id) { if ($data =~ /$id/) {1} } } } sub index { foreach my $data (@db) { foreach my $id (@id) { if (index($data,$id)+1) {1} } } }
UPDATE 2: to reiterate Ovid's point - The benchmark of my nested loop solution converges with Ovid's solution with just a hundred entries in each of your data sets
| <hand_wave> These are not the monks you're looking for </hand_wave> |
In reply to Re: need more efficient way to write this query script
by grep
in thread need more efficient way to write this query script
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |