[LON-CAPA-cvs] cvs: modules /raeburn reformat.pl

raeburn lon-capa-cvs@mail.lon-capa.org
Wed, 16 Jun 2004 20:23:46 -0000


raeburn		Wed Jun 16 16:23:46 2004 EDT

  Added files:                 
    /modules/raeburn	reformat.pl 
  Log:
  Converts a raw data file produced by the MSU scoring office from 
  scantron sheets with only five bubbles/row, to the scoring office's data
  format for scantron sheets with ten bubbles/row (as expected by LON-CAPA
  scantron grading). NOTE: 6-character codes are absent in the 5-bubble/row 
  sheets.
  
  

Index: modules/raeburn/reformat.pl
+++ modules/raeburn/reformat.pl
#!/usr/bin/perl;
# reformat.pl - converts a raw data file produced by the MSU scoring office 
# from scantron sheets with only five bubbles, to the scoring office's data 
# format for scantron sheets with ten bubbles (as expected by LON-CAPA i
# scantron grading). NOTE: 6-character codes are absent in the 5-bubble/row sheets. 
 
use strict;

if (@ARGV < 2) {
    print "Usage: reformat.pl <5-bubble-format-filename> <10-bubble-format-filename>\n";
    exit;
}
if (!-e "$ARGV[0]") {
    print "A file does not exist with the name you provided for the source file (5-bubble format)\n";
    exit;
}

open(FILE, "<$ARGV[0]");
my @buffer=<FILE>;
close(FILE);
if (($ARGV[1] eq '') || (-e $ARGV[1])) {
    print "The destination file already exists, or is an invalid filename\n";
    exit;
} 
open(FILE,">$ARGV[1]");
foreach my $line (@buffer) {
     chomp($line);
     my $desc = substr($line,0,76);
     $desc =~ s/(A\d{8})730/$1   /;
     my $answers = substr($line,76,13);
     if ($answers =~ m/\d/) {
         my @ans = split//,$answers;
         for (my $j=0; $j<@ans; $j++) {
             my $count = 0;
             if ($ans[$j] =~ m/^\d$/) {
                 while ($count<$ans[$j]-1) {
                     $desc .= " ";
                     $count ++;
                 }
                 $desc .= "1";
                 while ($count<9) {
                     $desc .= " ";
                     $count ++;
                 }        
             } else {
                 while ($count <10) {
                     $desc .= " ";
                     $count ++;
                 }
             }
         }
         print FILE $desc."\n\n";
     }
}
close(FILE);