I have to read in some CSV data from a flat data file, something like:
1.1,2.1,3.7 .... 1.4,4.4,2.2 . . .

(many columns and many more rows than columns)
The file has many columns and rows and is approximately 1gb in size. Each column has a different meaning. I am looking for the best way to keep the file in memory. At this time I have come up with the following:

Array of hashes: This way mimicks an array of struct in C e.g., $z = $Data[$RecNo]{'Intensity'}; . I have heard that keeping many small hashes around is wasteful, however. And, given the regularity of the data, this seems sub-optimal.

Hash of arrays: This way is backways from the Array of Hashes, but only uses as many hash entries as there are columns. $z = $Data{'Intensity'}[$RecNo];

use constant INTENSITY => 2;

Array of small arrays: $z = $Data[$RecNo][INTENSITY];

Small array of large arrays: $z = $Data[INTENSITY]; <br>[$RecNo];

Alternative, I can keep each line in memory and split the line at the time of access (this means that scalars will hold larger chunks).

Is there any sense of which of these methods are 'best' somehow? Any help would be appreciated.

(Also, how much memory do small scalars take? A small array? Any help from someone with Devel::Size would be appreciated!)

In reply to Array of Hashes vs. Array of Arrays vs Array of Lines vs ... 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.