in reply to Calculated % of data greater than $x in an array
If your input array is not ordered, you must inspect every element. grep is very handy for that task.
use strict; use warnings; use List::MoreUtils qw (firstidx); my $y = 10; my @array = (1, 4, 5, 7, 8, 9, 10, 20, 30, 40, 60); my $tot = scalar @array; my $i = firstidx { $_ > $y } @array; printf "%d%%", 100*($tot-$i)/$tot; __END__ 36%
|
|---|