#!/share/bin/perl -w #This is the more elaborate example of # a program that invokes system tasks (via system or backticks) # Supposedly it is a program that helps markers get listing # of assignments submitted in laboratory classes that they supervise. # It has a series of steps like unpacking files, copying files # running compilations etc. # The main program gets given a directory containing subdirectories # with the submissions for each student. It iterates through that # directory, invoking "processsubmission" on the contents of # each individual subdirectory. # The process submission code invokes tasks such as unpacking files # copying files, running compilations etc. sub processsubmission { system("gunzip A1.tar.gz"); $errcode = $? >> 8; if($errcode) { print "Corrupted gzip file?\n"; print STDERR "$_ has corrupt gzip file\n"; return; } system("tar -xf A1.tar"); if($errcode) { print "Corrupted tar file?\n"; print STDERR "$_ has corrupt tar file\n"; return; } #Remove any .class files system("rm -f *.class"); system("ls -l"); #has student submitted an A.java if(-r "A.java") { # if same as that supplied, remove it system("diff A.java ../A.java 1>/dev/null 2>/dev/null"); $code = $? >> 8; if($code == 0) { print "Removing unneeded A.java\n"; system("rm A.java"); } } system("cp ../A.class ."); @files = <*.{java,txt}>; foreach $file (@files) { print "\f$file:\n"; system("cat $file"); } system("javac B.java 2>&1 > compile_errs"); $compile_error = $? >> 8; if($compile_error) { system("tail -100 compile_errs"); print "\fAssignment not run because of compilation errors\n"; } else { $command = ' ulimit -t 5 java B 17 2>&1 < /dev/null > output tail -100 output '; system($command); } system("rm -f *.java *.class *.txt compile_errs output"); system("gzip A1.tar"); } #------------------------------------------------------------------------- #Checks an entry in lab file: # Submissions from students in subdirectories (along with a "control" # subdirectory); # other entries are for data files used in test script etc sub valid { $name = $_[0]; if($name =~ /^\.+$/) { return 0; } if($name eq "control") { return 0; } if(-d $name) { return 1; } return 0; } #--------------------------------------------------------------------------- # Main program starts here # # It wants two command line arguments tutor name, lab (directory) name $tutor = $ARGV[0]; $dirname = $ARGV[1]; if(! ((defined $dirname) && (defined $tutor))) { print STDERR <