perl.beginners
[Top] [All Lists]

Re: AW: How do I pick one random element from an array?

Subject: Re: AW: How do I pick one random element from an array?
From: Dave Tang
Date: Tue, 03 Nov 2009 17:30:05 +1000
Newsgroups: perl.beginners


On Tue, 03 Nov 2009 17:23:38 +1000, Thomas Bätzler <t.baetzler@xxxxxxxxxx> wrote:


Majian <jiannma@xxxxxxxxx> asked:
[...]
print "Array of random: $array[rand @array]\n";


I thoght it might work but it doesnt. I hope someone could give me an
idea to work this out...

TIMTOWTDY:

a) print "Array of random: $array[rand( @array ) ] \n";

b) print "Array of random: " . $array[rand @array] . "\n";

c) my $random_name = $array[rand @array];
print "Array of random: $random_name\n";

HTH,
Thomas

Hi Thomas,

Just a quick question, how does Perl interpret something like $array[0.7995038473872]?

Cheers,

Dave


--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
http://learn.perl.org/



<Prev in Thread] Current Thread [Next in Thread>