in reply to Re^4: Mean and standard deviation loop
in thread Mean and standard deviation loop

You need to partition the data - that is you need to process the subsets given by "Col 1" and "Col 3" (i.e. name and id).

So one way of doing this would be to use a hash that uses an array-ref to collect the data belonging to one partition:

my %partitions; while ( ... my @cols = split(',', $line); my $pname = "$cols[0]:$cols[2]"; $partitions{$pname} ||= []; push @{$partitions{$pname}}, $cols[3]; }
Then you can later process these partitions to calculate e.g. the mean:
use List::Util qw(sum); for my $pname (sort keys %partitions) { my $count = scalar @{$partition{$pname}}; my $sum = sum @{$partition{$pname}}; my $mean = $sum/$count; # std dev is left as an exercise }
This assumes that the data you want to process are in your "Col 4" only. If you need to include the other columns, simply push them also onto the array.

BEWARE: Untested code!