Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I know the code is basic but I've only just started using perl so any advice would be good. cheers!"print "This program will ask the user random questions from a file un +til all the questions have been answered."; if (open QUESTFILE, '<questions.txt') { $count=0; while ($q=<QUESTFILE>) { $question[$count]=$q; $count=$count+1; } } else { print "Could not read questions from file question.txt\n"; exit; } if (open ANSFILE, '>answers.txt') { $count=0; while ($a=<ANSFILE>) { $answer[$count]=uc($a); $count=$count+1; } } else { print "Could not read answers from file answers.txt\n"; exit; } srand; $times=0; while ($times<10) { $quest = int(rand ($#question+1)); print $question[$quest]; $ans = uc(<STDIN>); print ANSFILE $ans; $times=$times+1; } exit;"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Random lines from a file for a quiz
by sauoq (Abbot) on Aug 09, 2003 at 23:09 UTC | |
|
Re: Random lines from a file for a quiz
by cfreak (Chaplain) on Aug 10, 2003 at 00:11 UTC | |
|
Re: Random lines from a file for a quiz
by benn (Vicar) on Aug 10, 2003 at 01:44 UTC | |
|
Re: Random lines from a file for a quiz
by bobn (Chaplain) on Aug 10, 2003 at 06:26 UTC | |
|
Re: Random lines from a file for a quiz
by TStanley (Canon) on Aug 10, 2003 at 10:57 UTC | |
by Anonymous Monk on Aug 10, 2003 at 22:56 UTC | |
|
Re: Random lines from a file for a quiz
by waswas-fng (Curate) on Aug 11, 2003 at 00:01 UTC |