in reply to Re^4: optimize percentile counting in hash
in thread optimize percentile counting in hash

oh, below, not below or equal. Just switch the order of the two statements in the last loop. I usually only do the *100 when it's time to print, but I added it for you.
use strict; use warnings; my @data = get_data(); # or however you get them my %count; foreach my $datum (@data) { ++$count{$datum}; } my %percentile; my $total = 0; foreach my $datum (sort { $a <=> $b } keys %count) { $percentile{$datum} = $total / @data * 100; $total += $count{$datum}; }