You are overcomplicating things a lot. Some advice:

Use meaningful names for your vars and subroutines. %HoA, %hash_keys, $pointer, parse_hash or create_hash are very bad names because they don't say anything about the data inside or what they do.

Don't use global variables (%hash_keys, %AoH) to pass or get data from subroutines.

Try to simplify your structures, deep object trees lead to difficult to understand code. Also thing about the proper type to use in every case. For instance, it makes no sense to use a hash to store a list of ordered values.

And finally, modules are good only when they simplify your problem, to calculate the mean and deviation you don't really need a module!

use strict; use warnings; no warnings 'uninitialized'; my (%count, %sum, %sum2, %min, %max, @key); while(<>) { my (@val) = split /,/; if ($val[0]=~/^Year/) { @key = @val; } else { @key == @val or die "number of values and keys don't match" for my $i (0..$#key) { my $key = $key[$i]; next if $key =~/Year|Time/; my $val = $val[$i]; $count{$key} ++; $sum{$key} += $val; $sum2{$key} += $val*$val; $min{$key} = $val if (not defined $min{$key} or $val < $min{$key}); $max{$key} = $val if (not defined $max{$key} or $val > $max{$key}); } } } for my $key (sort keys %count) { my $count = $count{$key} my $sum = $sum{$key}; my $mean = $sum/$count; my $deviation = sqrt($sum2{$key}/$count - $mean*$mean); printf("key: %s, mean: %f, deviation: %f, min: %f, max: %f", $key, $mean, $deviation, $min{$key}, $max{$key}); }

oh, and consider using Text::xSV or Text::CSV_XS for parsing CSV files.


In reply to Re: Efficient use of memory by salva
in thread Efficient use of memory by K_M_McMahon

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.