Hi everybody.

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.txt
Then 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

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";
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.
Thanks

In reply to Using indexing for faster lookup in large file by anli_

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.