perlquestion
anli_
Hi everybody.
<p>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.<br>
My query would be something like '3005698' and the database I want to search has the following structure:</p>
<p>3005696;Homininae;Homo;Homo sapiens;<br>
3005698;9606;Homininae;Homo;Homo sapiens;<br>
3005690;90371;Enterobacteriaceae;Salmonella;Salmonella enterica<br>
3005700;9606;Homininae;Homo;Homo sapiens;<br></p>
<p>The output I would like would be something like:
Homininae,Homo,Homo sapiens</p>
<p>One way would be to use bash grep and do a search like:</p>
<code>grep "^3005698;" database.txt</code><br>
Then I could parse the output to make it pretty.
<p>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</p>
<code>
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";
</code>
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.<br>
Thanks