#!/usr/bin/perl
require 'parse.pl';
&parse_form;
print"Content-type:text/html\n\n";
print'<body>ข้อสอบแบบตรวจทันที เมื่อส่งคำตอบ<br>';
if ($v{'type'} eq "check") {
$right = 0;
foreach $k(sort keys %v){
if (substr($k,0,1) eq "q") {
$ra = join '','a',substr($k,1,5);
print "$k : Your ans=$v{$k}, Right ans=$v{$ra}<br>";
if ($v{$k} eq $v{$ra}) { $right++; }
}
}
print "<hr>You check the right = $right";
exit;
}
$fname = "quizjava.txt";
open(fn, "<$fname" );
@bfn = <fn>;
close(fn);
$cntr = @bfn;
$rand = $^T;
$dif = ($rand % 99) + 13;
for $r (1..10) {
$ind = (($rand / ($dif + $r)) + $r * 3) % $cntr;
push @keepar,$bfn[$ind];
}
print'<form method=post action=quizauto.pl>';
print'<input type=hidden name=type value=check>';
for $j (0..9) {
@recq = split (',',$keepar[$j]);
print $j+1,". $recq[1] (q$recq[0])<ul>";
print "<input type=radio name=q$recq[0] value=1 checked>$recq[2]<br>";
print "<input type=radio name=q$recq[0] value=2>$recq[3]<br>";
print "<input type=radio name=q$recq[0] value=3>$recq[4]<br>";
print "<input type=radio name=q$recq[0] value=4>$recq[5]<br>";
print "<input type=hidden name=a$recq[0] value=",substr($recq[6],0,1),">";
print "</ul>\n";
}
print'<hr><input type=submit value=SendAnswer>';
print'</form></body></html>';
จำนวน : 43 บรรทัด