Rohesia Hamilton Metcalfe wrote at Thu, 30 May 2002 17:28:45 +0200:

> #make array of cgi-scripts:
> @Scripts=("f-aaaa.cgi", "f-bbbbbb.cgi", "f-cccc.cgi", "f-dddd.cgi", "f-eeeeee.cgi",
> "f-ffffff.cgi");
> 
> # pick one at random
> srand;
> $RandomScript = $Scripts[int(rand(@Scripts))];
> 

I agree to Drieux that such a random selection looks strange.
I always feel nervous when i see Jeff's solution.
Not because of the underlying context what let's a floating value becomes an int,
but $element = $things[rand @things] hides the real information.
And there's double code (things), what is a real crime :-))

Let's look at an existing module:

use Tie::Pick;
tie my $randomScript => Tie::Pick => @scripts;

There's a disadventage, too.
Tie::Pick removes the element chosen,
but when it doesn't play a role or is even wanted,
I'd suggest the above solution.
Otherwise I'd prefer Jeff's solution.

Greetings,
Janek


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to