in reply to Uniformly Populating an Array with Elements of Another Array
I'm not sure what you mean by quick, but:
use strict; use warnings; my @elems = ("x", "y", "z"); my @tobepopulated = ("foo", "foo", "foo", "foo", "foo", "foo", "foo", +"foo", "foo", "foo"); die "Too few elements to populate" unless @tobepopulated ; my $inc = @elems / @tobepopulated; my $elIndex = $inc; for my $to (@tobepopulated) { $to .= "-$elems[$elIndex]"; $elIndex += $inc; } print "@tobepopulated";
Prints:
foo-x foo-x foo-x foo-y foo-y foo-y foo-z foo-z foo-z foo-z
and may be something like what you are after.
|
|---|