I have a perl script, that goes through a couple of gig worth of files and generates a report.
In order to calculate percentile i am doing the following
my @values = 0;
while (my $line = <INPUTFILE>){
.....
push(@values, $line);
}
# Sort
@values = sort {$a <=> $b} @values;
# Print 95% percentile
print $values[sprintf("%.0f",(0.95*($#values)))];
This obviously saves all the values upfront in a array and then calculates the percentile, which can be heavy on memory (assuming millions of values), is there a more memory efficient way of doing this?