Perl Grading

Our file server has a folder into which students “Hand In” files by dropping completed assignments into.  Within this folder, I move files into a folder for each assignment.  Any files not in a folder are new, and still need to be graded.

To prevent students from copying another students assignment, the Hand In folder is write-only.

The down side to this, is students can’t see what they have handed in.  It’s a laborious task to look in each folder for each student’s work — 20 students times 20 assignments is a lot of individual searching.

To speed the process, I decided to write a Perl Script to do this for me and present a list of each assignment and who has handed in a file for each assignment.

#!/usr/local/bin/perl
$folder = '.';
@ignoreFiles = ( ".", "..", ".DS_Store" );

use Cwd 'abs_path';
$folder = abs_path($folder);

@incompletes = ();
@unchecked = ();
@usernames = ();
%assignments = ();

print "Processing $folder\n";

opendir(DIR, $folder) or die $!;

while (my $file = readdir(DIR)) {
next if ($file ~~ @ignoreFiles);

# ... for a file:
if (-f "$folder/$file") {
if ($file =~ /^-/) {
#print "Incomplete: $file\n";
push @incompletes,$file;
}
else {
#print "Unchecked: $file\n";
push @unchecked,$file;
}
}

# ... for a folder:
else {
my $title = $file;

print "Checking Assignment $title...\n";
opendir(A, $file) or die $!;

while (my $f = readdir(A)) {
next if ($f ~~ @ignoreFiles);
$ls = qx(ls -ld -- "$folder/$file/$f");
@attrib = split(/ +/, $ls);
my $owner = $attrib[2];
push(@{$assignments{$title}}, $owner);
if(not($owner ~~ @usernames)) {
# build list of students
push @usernames,$owner;
}
}
closedir(A);
}
}
closedir(DIR);

#print "Hand In";
#foreach my $a (keys%assignments) { print ",$a"; }
#foreach my $s (@usernames) {
#print "\n$s";
#foreach my $a (keys%assignments) {
#$handedin = @assignments{$a};
#if($s ~~ @$handedin) { print ",10"; }
#else { print ",0"; }
#}
#}

foreach my $a (keys%assignments) {
 print "\nAssignment: $a\n";
 $handedin = @assignments{$a};
 foreach my $s (@$handedin) {
 print "$s\n";
 }
}
exit 0;

Please excuse any perl faux pas I have committed.  I have not written Perl in over 10 years, and only briefly in an undergraduate Programming Language Survey course.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: