#!/usr/bin/perl -w # my quiz use strict; use CGI qw(param); my $max; my @question; my @correct; my @answer; my $i = "0"; my $j = "0"; my $k = "0"; my $score = "0"; my (@A, @B, @C, @D); my $who = param("name"); my $surname = param("surname"); open(QSTNS, "questions.txt") || die "cannot open questions.txt $!"; while () { $_ =~ /^(Quiz)(\d)$/; $max = $2; } close(QSTNS) || warn "cannot close questions.txt $!"; while ($k < $max) { push (@answer,param("answer$k")); $k++; } print <Quiz

WELCOME TO MY QUIZ!

Firstbit if (param()) { open(QSTNS, "questions.txt") || die "cannot open questions.txt $!"; while() { if ($_ =~ /^A\d:/) { chomp; s/A\d://; push (@correct,$_); } } close(QSTNS) || warn "cannot close questions.txt $!"; while ($j < $max) { if ($answer[$j] eq $correct[$j]) { $score++; #print "

score: $score"; } #print "

j: $j"; $j++; } #print "

@correct, @answer"; print "

$who $surname, you scored $score"; open(LOGS, ">>log.txt") || die "cannot append log.txt $!"; print LOGS "$who $surname scored $score\n"; close(LOGS); } else { open(QSTNS, "questions.txt") || die "

cannot open questions.txt $!"; while() { if ($_ =~ /^Q\d/) { chomp; push (@question,$_); } if ($_ =~ /^C\d:/) { chomp; s/C\d://; $_ =~ /([^,]+),([^,]+),([^,]+),([^,]+)/; push (@A,$1); push (@B,$2); push (@C,$3); push (@D,$4); } } #print "

A: @A"; close(QSTNS); print <

Please enter your first name:

Please enter your surname: Startform while ($i < $max) { print <$question[$i]
       $A[$i]
       $B[$i]
       $C[$i]
       $D[$i]
Loop $i++; } print < Endform } print < Endbit