in reply to Re: Text CSV_XS memory crash
in thread Text CSV_XS memory crash

Since I'm acting on the column values, I think I have to read every line into the array, in order to pull out the first value of every row to get a column. Perhaps I'm missing a CSV_XS method for selecting the column instead of reading in every row?

Replies are listed 'Best First'.
Re^3: Text CSV_XS memory crash
by Anonyrnous Monk (Hermit) on Feb 02, 2011 at 15:41 UTC
    ...in order to pull out the first value of every row to get a column.

    Not sure I'm understanding you correctly, but if you only need the first column of every row, why not store only the first column (that would at least reduce memory usage somewhat).

    The getline() method returns a reference to an array holding the columns. In other words, $row->[0] would be the first column.

    If, OTOH, you actually do need access to all columns of all rows simultaneously, I'm afraid there's not much you can do except to upgrade memory (or write out the data into another (DB) file format that allows direct random access to individual fields).

      Hmm, I'm starting to see the light. I only need to work on one column at a time, read in the column, select min/max and distinct, then load the next column and repeat.

      I'll go back to the drawing board, I think I'm pretty close...

        select min/max and distinct

        FWIW, things like min/max (and many other statistics) can also be computed sequentially (or incrementally), i.e. without storing all values in memory prior to starting the computations.  Maybe that's worth reconsidering...

        Have you considered using DBD::CSV, or alternativly importing your data into a database of some sort?