I know how to take a random line from a file but I need to use up all the questions in the file without using any of the questions more than once. I've looked around the site but couldn't find any examples. The only idea I have is turning the filehandle into an array. Anyway any help would be appreciated. Here's the code I have so far:
"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;"
I know the code is basic but I've only just started using perl so any advice would be good. cheers!

In reply to Random lines from a file for a quiz by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.