I apologize if this is an utterly clueless question, but I'm a newbie so here goes:

All I want to do is to be able to correlate two entries in a very large text file, for instance the file is of the format:

12 4433 13 4433 14 4476 15 4477 16 4477

...and so on with tabs separating the columns. I'm going to be accessing this array hundreds of thousands of times. Now the approach for this that seemed obvious to me was just like this:

while (chomp($input=$handle->getline)) { @temp=split("\t",$input); $index[$temp[0]]=$temp[1]; }

Which is great, now we have $index(field 1 value) = field 2 value, which is what I wanted. and works great for the original 40 meg text file.

The problem comes with the new text file, which is almost 400 megs (many millions of entries). My system slows to a crawl and eventually seizes up. I assume this is most likely memory issues (only 256M physical due to a RAM blowout, another 500 M swap) or something, but I'm not sure.

Is there a better way to do this kind of thing for a huge text file like this?


In reply to Very large text file - simple indexing by Anonymous Monk

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.