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;
In reply to Re: Split the array elements in ranges
by hdb
in thread Split the array elements in ranges
by viktor
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |