#!/usr/bin/perl $problems ="problems.dat"; $students ="students.dat"; open(PROBLEMS, "< $problems") || die ("couldn't open $problems: $!\n"); @problemcontents =; close(PROBLEMS); open(STUDENTS, "< $students") || die ("couldn't open $students: $!\n"); my @zadachi; my $line; # parsing the file for $line (0..@problemcontents) { $problemcontents[$line] =~ s/\s//; @{$zadachi[$line]}=split(/\,/, $problemcontents[$line]); # print "$filecontents[$line]\n"; # print "${$zadachi[$line]}[2]\n"; } my $filelength=scalar(@zadachi); # print "file length is $filelength\n"; my @oldzadachi=@zadachi; @zadachi=(); for $line (0..$filelength) { my $numzadach=scalar(@{$oldzadachi[$line]}); # print "line is $line, numzadach is $numzadach\n"; if ($numzadach) { # print "Pushing $line to zadachi\n"; push(@zadachi,@oldzadachi[$line]); } } my $numlines=scalar(@zadachi)-1; #print "We finished parsing now... there are $numlines lines\n"; my $numstudents=0; while () { $numstudents++; chomp $_; print "$numstudents. $_ "; for $line (0..$numlines) { $invalid=1; $numzad=scalar(@{$zadachi[$line]}); while ($invalid) { # print "zadachi is $numzad, line is $line, numlines=$numlines\n"; $num=int(rand($numzad)); $morenum=int(rand($numzad)); # print "$num, $morenum\n"; $invalid=($num >= $morenum); } print "& ${$zadachi[$line]}[$num]\\qquad & ${$zadachi[$line]}[$morenum]\\qquad \t"; } print "\\\\ \\hline \n"; if ($numstudents==28) { print "\\end{tabular} \\newpage \n \\begin{tabular}{||l||c|c|c|c|c|c|c|c|c|c|}\n \\hline "; } } close(STUDENTS);