I don't see how it could be something I am doing though.
q39 => reading
q25 =>
q40 => false
is a partial printout of the results page. The following code is the HTML for it
<td><p>39) question goes here</p>
<blockquote>
<p> sub question goes here
</blockquote>
<p>
<input name="q39" type="radio" value="reading">
reading
<input name="q39" type="radio" value="writing">
writing </p></td>
</tr>
<tr>
<td><p>40) True or false? question goes here</p>
<blockquote>
<p> sub question here</p>
</blockquote> <p>
<input name="q40" type="radio" value="true">
true
<input name="q40" type="radio" value="false">
false </p></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</form>
And the following is how I'm checking the last two questions (by the way, ALL questions have the same format and all are coming back wrong).
if ($questions{"39"} eq "reading")
{
$right++;
}
else
{
$wrong++;
}
if ($questions{"40"} eq "false")
{
$right++;
}
else
{
| [reply] [d/l] [select] |
I assume you're populating %questions with the form data. If this is the case, then you want to be checking $questions{'q40'}, not $questions{'40'}. (it must exactly match the name of the field input).
Of course, if you have more complicated logic populating your questions hash, this may not be the problem.
When in doubt, dump the contents of %questions, so you know what you're dealing with:
use Data::Dumper;
warn Dumper( \%questions );
Run the script, and then check your webserver's error logs.
Oh, and being lazy, if it's all just multiple choice, like what you've shown, I'd probably just store all of the answers, and loop through them, rather than hard code as you have:
# assume %questions is populated.
my %answers = {
...
q39 => 'reading',
q40 => 'false',
};
foreach my $num ( keys %answers ) {
if ( defined($questions{$num})
and $questions{$num} eq $answers{$num}) {
$right++;
} else {
$wrong++;
}
}
| [reply] [d/l] [select] |