#!c:/perl/bin/perl -w $|++; use strict; my @questions = ( { question => 'What perl site is a great learning tool?', answers => { perlmonks => 1, # 1 for correct answer javajunkies => 0, # 0 for incorrect answer microsoft => 0 } }, { question => 'Pick a valid color:', answers => { red => 1, # multiple correct answers blue => 1, # permitted sheep => 0, cow => 0 } } ); my $correct = 0; for my $question (@questions) { print "\n\nQ: ", $question->{'question'}, "\n", 'A: ', join(', ', keys %{$question->{'answers'}}), "\n\n"; print 'Your answer: '; chomp( my $ans = ); ++$correct if ($question->{'answers'}->{lc $ans}); } print "\n\nYour grade is ", +(int($correct/@questions*100)), "%.\n", "You answered $correct questions correctly.\n\n";