The probable reason is that you are storing numeric values as PVs--their string representation as read from the file--in addition to IVs--their numeric representation--the generation of which you are deliberately forcing with this code:

if ($self->datatype->[$_] =~ /^(?:TINYINT|MEDIUMINT|SMALLINT|INT|INTEGER|BIGINT|FLOAT|DOUBLE)$/ +) { $hr_returnvalue->{$CurrentColumnName} *= 1; # Multiply by 1 to create a numeric value. }

Having initially loaded the value as a string (PV), when you force it to be converted to a numeric value (IV), the string value will be retained so that if you later decide to use it in a string context, the (inverse) conversion does not have to be repeated.

Eg. After the *= 1;, the PV is still there, but you gained an IV. Essentially you've increased the size of the SV rather than reduce it (as I assume you intended):

C:\test>perl -MDevel::Peek -E"my $x = '12345'; Dump $x; $x *=1; Dump $ +x" SV = PV(0x6cf50) at 0xc74e8 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x67758 "12345"\0 CUR = 5 LEN = 8 SV = PVIV(0xaf018) at 0xc74e8 REFCNT = 1 FLAGS = (PADMY,IOK,pIOK) IV = 12345 PV = 0x67758 "12345"\0 CUR = 5 LEN = 8

A fix would be to perform the string->numeric conversion before storing the value:

for( 0 .. $#{$self->columns} ) { $CurrentColumnName = $self->columns->[$_]; if( !(defined $self->flatfield_start->[$_] and defined $self->flatfield_length->[$_] ) ) { # Field is missing interface_start, interface_length or both, skip + it. next; } if ($self->datatype->[$_] =~ /^(?:TINYINT|MEDIUMINT|SMALLINT|INT|INTEGER|BIGINT|FLOAT|DOUB +LE)$/ ) { $hr_returnvalue->{$CurrentColumnName} = 0 + substr( $textinput, $self->flatfield_start->[$_], $self->flatfield_length-> +[$_] ); }else { $hr_returnvalue->{$CurrentColumnName} = substr( $textinput, $self->flatfield_start->[$_], $self->flatfield_length +->[$_] ); $hr_returnvalue->{ $CurrentColumnName } =~ s/^\s*(.*?)\s*$/$1/; # Trim whitespace } # Fill empty fields with that field's default value, if such a value +is defined

That should reduce the size of the final data structure significantly if there are many numeric fields.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Reading (the same) data in different ways & memory usage by BrowserUk
in thread Reading (the same) data in different ways & memory usage by Neighbour

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.