in reply to Filling buckets
use Data::Dumper; my @array = 'a' .. 'w'; my $num = 3; # buckets my $cnt = @array; # total items my $base = int($cnt/$num); # } my $left = $cnt % $num; # } $cnt = ($base * $num) + $left my @buckets; for (1..$num) { push @buckets, [ splice(@array,0,$base + ($left-- > 0 && 1) ) +]; } print Dumper(\@buckets);
|
|---|