in reply to Uniformly Populating an Array with Elements of Another Array
Here's AWTDI. Where the other solutions seem to be mostly algebraic, this one actually distributes.
use strict; use warnings; my @elems = qw( x y z ); my @tobepopulated = ('foo') x 10; print "$_\n" for uniformly_distribute( \@elems, @tobepopulated ); sub uniformly_distribute { my $elems_ar = shift; my @c = map { [] } @$elems_ar; while ( @_ ) { for ( reverse ( 0 .. $#c ) ) { push @{ $c[$_] }, join '-', $elems_ar->[$_], pop @_ if @_; } } map @$_, @c }
|
|---|