Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
This is relatively can be done by looping through values of any array and count how many of array elements are greater than $x and then calculate the percentage as follow. I am just wondering if there is another way to avoid the looping.
#!/usr/local/bin/perl use strict; my $y= 10; my @array =(1, 4, 5, 7, 8, 9, 10, 20, 30, 40, 60); my $greater = 0 ; if(my $y >= 1){ foreach my $elem (@array){ if ($elem > $y){ $greater++; } } my $pecentgreater = $greater /(scalar @array) *100; print "Percent Greater Than y = $pecentgreater\n";
|
|---|