hi , i have this problem in which i'm using grep function but the process is tooooo slow.

i have a file that has some numbers in it like :

in.txt __DATA__ 13454 34456 1342 5667 987 3354 145
and i have a set of numbers in the @array (form 1 .. 1000000) - numbers are in that range but there is no 1000000 numbers but 400000 (some are missing). so what i wish to do is go through my file and see if the number in the file is in the @array. if it is then it is enough to print it out.
use strict; use warnings; my @array; # contains numbers (1..1000000) ~ 400000 numbers my @array1 = sort @array; # sort it to speed up the process?? open (in , "<", "in.txt") || die "$!"; while(<in>){ m/^(\d+)/; my @a = grep {$_ == $1} @array1; print "@a, " if (@a); } close in;
to run the search it takes me ~150 min. does any one knows any trick to speed this up.(without using databases SQLite, mySql ....)

so basically what i'm asking for is a way to replace grep efficiently for this case only (if that is possible)

thnx

update :

hashing it (@array) would take up too much RAM(because here i stated the most simplified example and not the actual thing - to complex and unnecessary)

update 2:

the in file is too big to be stored in memory (on a machine with 512 MB of ram) :). that is also important fact that i neglected :) but idea is ok !

update 3:

in file has 0.3 billion rows (all numbers, some repeating)(300000000 (billion in my language is 1000x more than in english - so to be sure))

i don't know where wol is going with 'the' question but there are other things in memory living along those numbers :)


In reply to 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.