Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: Seek one liner for distributing an integerby TedPride (Priest) |
on Sep 22, 2004 at 07:32 UTC ( [id://392862]=note: print w/replies, xml ) | Need Help?? |
$result{$array[$n++]} = int($num / ($#array + 1)) + ($num % ($#array + 1) > $n) while ($n <= $#array + 1); This produces the results you want in one run through @array - 5 steps - rather than $num steps. One of the other examples given above also attempts to do this, but I can't get the code to work, so here's mine. NOTE: $n is created global here, overwriting any other global or local $n in use. I couldn't do a my statement without using a second line.
In Section
Seekers of Perl Wisdom
|
|