in reply to optimize percentile counting in hash

In my opinion, you're writing code where you don't need to write code. Almost everything (other than the use of a hash instead of an array) you're trying to do can be done by the module Statistics::Descriptive and in much more compact form. I won't guarantee it will run much faster, but the routines should be easier to manage:

To bin data, for example:

#!/usr/bin/perl use warnings; use strict; use Statistics::Descriptive; # # Warning: untested code. # my @data = (1,7,2,19,3,4,21,1092,6); my $stat = Statistics::Descriptive::Full->new(); $stat->add_data(@data); $stat->sort_data(); print $stat->percentile(25);

Replies are listed 'Best First'.
Re^2: optimize percentile counting in hash
by max210 (Novice) on Mar 21, 2008 at 14:02 UTC

    Great Help :)
    Although, when I run it, it says, Can't locate Statistics/Descriptive.pm in @INC.
    I apologize for asking simple questions, but kindly bear with it, am new to perl
    Thanks again.

      The module Statistics::Descriptive is a Perl CPAN module, and how you add a Perl module will change depending on the flavor of Perl you are running.

      Are you running Perl on a Windows box using Active State Perl or on a Unix machine?

      In Active State, you would use the command 'ppm' to launch the tool to install modules, and in Unix, you can use the command:

      perl -MCPAN -e shell
      To start the process of accessing the CPAN repository. If you do not have Internet access from your machine, you may have to download the modules manually.

      If you need to know more, there is this node on Perl Monks that has all kinds of information about installing modules.

      Update: added PM node on module installation.
        Awesome, Thanks a lot.