Front page | perl.beginners |
Postings from March 2002
random word from array
Thread Next
From:
Wytch
Date:
March 27, 2002 16:02
Subject:
random word from array
Message ID:
20020327232517.51602.qmail@onion.perl.org
I decided to write a little script to help choose who will make the tea on
our gaming night [there is always an argument!]
I thought I was doing quite well but it seems I am picked on by the
[non]random script I wrote! It seems to default to the first word in the
array.
I used rand @array;
I think perhaps that I am thinking about it too simply and perhaps I need to
involve more math - but I am not good at maths [though I am willing and a
quick learner...lol] ! so can anyone point me in the right direction?
#!c:/perl/perl.exe
@tea = "Meba", "Shaun", "Mark", "Jason", "Rick", "Dan";
#below is the problem area I think - perhaps rand is not appropriate here?
#or I haven't phrased it right?
#I have looked through masses of documentation and faqs but can't find a
thing.
#Am I blind or just dim?
$get = rand @tea;
$who = $tea[$get];
$affirm = "The lucky tea maker is ";
$result = $affirm.$who;
$fail = "Sorry I wasn't listening. Try again!\n";
print "Enter y to see who will make the tea: ";
$input = <STDIN>;
chomp $input;
if ($input eq "y") {
$a= true;
}
if ($a) {print $result
}
else
{
print "$fail" };
Thread Next
-
random word from array
by Wytch