Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Perl hit counter for multiple ranges, optimization or options in other languages?

by rjt (Curate)
on Aug 07, 2013 at 22:41 UTC ( [id://1048450]=note: print w/replies, xml ) Need Help??


in reply to Perl hit counter for multiple ranges, optimization or options in other languages?

You're asking for a frequency distribution. Statistics::Descriptive makes very quick work of this (and much more):

use Statistics::Descriptive; my @ranges = (19, 29, 39); # 1..19, 20..29, 30..39 my $stat = Statistics::Descriptive::Full->new; $stat->add_data( 12, 14, 15, 20, 21 ); my %dist = $stat->frequency_distribution(\@ranges); printf " %5d: %4d\n", $_, $dist{$_} for @ranges;

Output:

19: 3 29: 2 39: 0
use strict; use warnings; omitted for brevity.

Replies are listed 'Best First'.
Re^2: Perl hit counter for multiple ranges, optimization or options in other languages?
by SaktiMonk (Initiate) on Aug 07, 2013 at 22:43 UTC
    I didn't know about this module, but sounds like a great alternative for my problem, thanks!
Re^2: Perl hit counter for multiple ranges, optimization or options in other languages?
by SaktiMonk (Initiate) on Aug 10, 2013 at 01:25 UTC
    worked out great, now the script runs much more smoothly, thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1048450]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-18 04:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found