in reply to Re: Randomly generating histograms
in thread Randomly generating histograms

i'd use map for a one liner to replace for:
map ++$array[rand $elements], 1..$sum;
also, you can drop the int, like i have. and you mean
$array[$_] ||= 0 for 0..$elements-1;
don't you?

~Particle ;̃

Replies are listed 'Best First'.
•Re: Re: Re: Randomly generating histograms
by merlyn (Sage) on Mar 26, 2002 at 22:24 UTC
    i'd use map for a one liner to replace for:
    map ++$array[rand $elements], 1..$sum;
    I wouldn't. This is clearer, faster, and one character shorter:
    ++$array[rand $elements] for 1..$sum;
    Help stamp out void maps and greps!

    -- Randal L. Schwartz, Perl hacker

      too true, too true! i usually take that position--i learned it here. i guess i just couldn't resist showing off a bit.

      thanks for keeping me honest, merlyn

      ~Particle ;̃