Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Split the array elements in ranges

by hdb (Monsignor)
on Apr 16, 2013 at 10:17 UTC ( [id://1028868]=note: print w/replies, xml ) Need Help??


in reply to Split the array elements in ranges

What you want is some Histogram. Have a look at CPAN. Otherwise, use a hash for counting:

use strict; use warnings; my @array=qw ( 1 2 3 10 11 12 13 20 21); my $bin = 10; my %hist; map { $hist{ (int(($_-1)/$bin)+1)*$bin }++ } @array; print join ",", map { ($_-9)."-$_ $hist{$_}" } sort keys %hist;

Replies are listed 'Best First'.
Re^2: Split the array elements in ranges
by viktor (Acolyte) on Apr 16, 2013 at 12:24 UTC
    thanks :)

Log In?
Username:
Password:

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

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

    No recent polls found