What about getting the job done in less than a half of second? (no DBMs, no Hashes):

use strict; use warnings; my ($file1, $file2) = @ARGV; my $ids = 1000000; # last id my $bin=0; substr($bin,$_,1,pack ("c",0)) for (0..$ids); # Create the index open my $fh1, "<", $file1 or die $!; while (my $id = <$fh1>){ chomp $id; substr($bin, $id,1,pack ("c",1)); } close $fh1; # Search $ids from file 2 open my $fh2, "<", $file2 or die $!; while (my $id2 = <$fh2>){ chomp $id2; print "$id2\n" if ((unpack "c",substr ($bin,$id2,1)) == 1); } close $fh2;

file1 contains 400000 numbers between 0 and 1000000. file2 contains 10000 numbers in the same range. Processing both takes less than half a second.

time perl sp.pl file1 file2 > /dev/null real 0m0.448s user 0m0.448s sys 0m0.000s

A bit of explanation: The program constructs an scalar ($bin) containing 1000000 of 0s. While processing the index (the first list of ids), it substitutes every 0 at position $id with a 1.

Then, it reads the second file of ids and checks if at position $id2, the $bin scalar has a 0 (not seen previously) or a 1 ($id already seen in the first file).

Hope this helps

citromatik


In reply to Re: searching through data by citromatik
in thread searching through data by baxy77bax

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.