in reply to Re^2: hash checking
in thread hash checking

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++; } }