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 :)