in reply to need more efficient way to write this query script

My quick suggestion would be to use index instead of this regex $data =~ /$id/

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



grep
<hand_wave> These are not the monks you're looking for </hand_wave>

Replies are listed 'Best First'.
Re: Re: need more efficient way to write this query script
by Anonymous Monk on Aug 16, 2002 at 07:09 UTC
    Geek .sig critique...

    Confucius say: have nerve to create fancy-dan "funny" .sig regarding sacred A New Hope - better get quote right.

    grep say "These are not the monks you're looking for"

    Obi-Wan-Kenobi actually say "These aren't the the monks you're looking for"

    Moral of story: grep must actually use actual Obi-Wan quote before constructing fancy-dan HTML .sig.
      Gosh, I remember when we used to call that "Star Wars".

      "These aren't the pants you're looking for."