in reply to breaking an array into nearly equal parts
But I prefer the one posted by TedPride.#!/usr/bin/perl -w use strict; my @A= 1..int(rand(21)); print "\@A: ",scalar @A,$/; my @parts; $parts[3-$_] = [splice @A,0, @A%$_?int(@A/$_)+1:int(@A/$_)] foreach (r +everse 1..3); #@A is empty now. print join( ' ',@$_)," : ",scalar @$_,$/ for @parts;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: breaking an array into nearly equal parts
by nicoaimetti (Acolyte) on Dec 15, 2005 at 04:41 UTC |