i have a file that has some numbers in it like :
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.in.txt __DATA__ 13454 34456 1342 5667 987 3354 145
to run the search it takes me ~150 min. does any one knows any trick to speed this up.(without using databases SQLite, mySql ....)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;
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |