#!/usr/bin/perl use strict; use warnings; use CGI qw/:standard/; my @words = ( 'amiko::friend', 'kafo::coffee', 'filo::son', 'kuko::cake', 'frato::brother', 'lakto::milk', 'instruisto::teacher', 'pano::bread', 'knabo::boy', 'sukero::sugar', 'patro::father', 'teo::tea', 'akvo::water', 'butiko::shop', 'limonado::lemonade', 'papero::paper', 'plumo::pen', 'taso::cup', ); srand ( time() ^ ($$ + ($$ << 15)) ); my $answer = param('answer'); ($answer) = ( $answer =~ /^(\w*)$/ ); my $language = param('language'); $language = 'Esperanto' unless $language; my $last_question = param('last_question'); ($last_question) = ($last_question =~ /^(\w*)$/); my ($esperanto, $english) = split /::/, @words[rand(scalar(@words))]; my $question = sprintf("%s\n", $language eq 'Esperanto' ? $esperanto : $english); my $match = gradeit( $last_question, $answer ); sub gradeit { my $first = shift; my $second = shift; my $together; if ($language eq 'Esperanto') { $together = join "::", $first, $second; } else { $together = join "::", $second, $first; } my $match = "No. $first != $second"; foreach my $word (@words) { if ($word eq $together) { $match = "Correct. $first = $second"; last; } } return $match; } param('last_question', $question); print header, start_html( -title => 'Esperanto Quiz' ), h1('Esperanto Quiz'), p( b( 'Question: '), 'What does ', b($question), ' mean?' ), p( $match ), start_form, textfield( -name => 'answer', -size => 40, -maxlength => 40 ), br, radio_group( -name => 'language', -values => ['English', 'Esperanto'], -default => 'Esperanto', -linebreak => 'true'), hidden( 'last_question' ), submit, end_form, end_html;