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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |