anli_ has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to get a grip on indexing and how it works.
My current problem is that I would like to make a simple text lookup in a very large file.
My query would be something like '3005698' and the database I want to search has the following structure:
3005696;Homininae;Homo;Homo sapiens;
3005698;9606;Homininae;Homo;Homo sapiens;
3005690;90371;Enterobacteriaceae;Salmonella;Salmonella enterica
3005700;9606;Homininae;Homo;Homo sapiens;
The output I would like would be something like: Homininae,Homo,Homo sapiens
One way would be to use bash grep and do a search like:
grep "^3005698;" database.txtThen I could parse the output to make it pretty.
Using perl, they way I would normally do it would be to generate a hash of the database and then do my lookups from that, like so
The problem I have with this is that the database is around 30Gb, so it would be a very slow and memory consuming process. So my question is, can I somehow index the database, so I know where in the file the query '3005698' resides, to speed up this process.open IN, '<', "/path/to/database.txt"; my %hash; while (<IN>) { my ($first,@array) = split(/;/, $_); @{ $hash{$first} } = @array; } close IN; print $hash{'3005698'}[1] . " "; print $hash{'3005698'}[2] . " "; print $hash{'3005698'}[3] . "\n";
Thanks