Hello so, I am very new to perl, I need to take the post data from a quiz and compare it against an array containing the correct answers. Now the answer key is to be generated from a text file, that goes like the following:
1. question?
*a. answer
b. answer
c. answer
the * means the correct answer, so I need to take very line in the file starting with a * to create the answer key. then I need to compare the post data (results from the user's quiz against the answer key I generate. my problem appears to be generating the answer key from the file. so far I have tried this:

my @answers = (); open(my $file, "quiz4.txt"); while (my $line = <$file>) { if ($line =~ /\A\*/) { $line = substr($line, 1); $answer = substr($line,0); push(@answers, $answer); } }
I am attempting to find the line starting with *, then add it to an array called answers. then I hope to get the following to work to do a basic correct or wrong check:
for ($i=0; $i<=9; $i++) { $thisname = $name[$i]; if (exists $formHash{$thisname}) { if ($formHash{$thisname} eq $answer[$i]) { print "Correct answer"; } else { print "incorrect answer"; } } }
Any help, guidance, or advice is greatly appreciated! Thank you in advance!


In reply to What can I be doing wrong with this array in this particular section? by tjox

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.