On Aug 2, Dan Klose said:
my %hash_of_arrays2;
for (keys %hash_of_arrays) {
my @array_of_data = exists($hash_of_arrays{$_})
[EMAIL PROTECTED]
:();
Given that you're iterating over the list of keys in %hash_of_arrays,
there's NO reason to be using exists() here.
my @array_of_data = @{ $hash_of_arrays{$_} };
my $mean = mean([EMAIL PROTECTED]); #GET MEAN
my $std_dev = dev([EMAIL PROTECTED]); #GET STANDARD DEV
There's no reason to make a COPY of the array and then dereference. I'd
suggest doing:
my $data = $hash_of_arrays{$_};
my $mean = mean($data);
my $std_dev = dev($data);
push @{$hash_of_arrays2{$_}}, $mean;
push @{$hash_of_arrays2{$_}}, $std_dev;
You can do both at once:
$hash_of_arrays2{$_} = [ $mean, $std_dev ];
}
You can make that for loop into one statement:
my %hash_of_arrays2 = map {
$_ => [ mean($hash_of_arrays{$_}), dev($hash_of_arrays{$_}) ]
} keys %hash_of_arrays;
for (sort {$hash_of_arrays2{$a}[0] <=> $hash_of_arrays2{$b}[0]}
keys %hash_of_arrays2) {
print "$_, $hash_of_arrays2{$_}[0], $hash_of_arrays2{$_}[1]\n";
}
There's no way to eliminate the second loop, because you need to have all
the data calculated before you can sort them.
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://japhy.perlmonk.org/ % have long ago been overpaid?
http://www.perlmonks.org/ % -- Meister Eckhart
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>