>>>>> "PK" == Parag Kalra <[email protected]> writes:
PK> use strict;
PK> use warnings;
good.
PK> my %mean_values;
PK> while(<DATA>){
PK> chomp;
PK> my ($key, $value) = split (/\t/,$_);
PK> if ( exists $mean_values{$key} ){
PK> push @{$mean_values{$key}}, $value;
PK> } else {
PK> ${$mean_values{$key}}[0] = $value;
PK> }
PK> }
no need for all that extra code. perl will autovivify references for
you. just push as if it were there.
push @{$mean_values{$key}}, $value;
PK> foreach (keys %mean_values){
don't use $_ in loops. named variables are better
PK> my $cnt = @{$mean_values{$_}};
PK> my $sum = 0;
PK> foreach(@{$mean_values{$_}}){
especially don't do nested loops with $_. it is even harder to follow
which loop variable you are looking at.
PK> $sum = $sum + $_;
$sum += $_ ;
uri
--
Uri Guttman ------ [email protected] -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/