in reply to Filling buckets
sub split_into { my ($n, @from, @to) = @_; while (@from) { push @{$to[$i++]}, shift @from; i %= $n; } @to; } @results = split_into(3, 'a' .. 'z');
Update: It's a lot like Tilly's last one. But it doesn't have the bad memory behavior. (Ben's has an array that marches downward indefinitely in memory, which is bad.) Mine also has the benefit of not requiring the explicit initialization of the destination array.
|
|---|