ClasslistGenerator

From WeBWorK_wiki
Revision as of 14:26, 3 January 2013 by Goehle (talk | contribs) (Created page with "#!/usr/bin/perl #Classlist generator script # This script takes in a CSV file (such as those generated by Banner) # and creates a lst file which can be used to import student...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
  1. !/usr/bin/perl
  1. Classlist generator script
  2. This script takes in a CSV file (such as those generated by Banner)
  3. and creates a lst file which can be used to import students into a class.
  1. Currently the script assumes that the input file is a CSV file with the
  2. following fields
    1. STUDENT_ID,LAST_NAME,FIRST_NAME,MI,STREET1,STREET2,CITY,STATE,ZIP,textbox15,EMAIL,PHONE_1,GENDER,ETHNICITY,PHONE,textbox23,textbox32,HONORS,TERM,SUBJECT,COURSE_NUM,SEC,DEPT,REG_STAT,TITLE,INSTRUCTOR
  1. The first line of the CSV file should contain lables and data entries are
  2. only seperated by tabs. Currently the script strips of the student ID, the
  3. firrst and last names, the section number and email address. The username
  4. for the student is the email address username.
  1. Those who are familiar with perl scripts should be able to modify this setup
  2. to deal with input files that have a different format.

if (! $#ARGV eq 1) {

   print "Usage: ./classistgenerator <banner csv> <target classlist>\n";
   exit;

}

  1. Open source and target files as provided via command line

open (SOURCE, "<", $ARGV[0]) or die "Can't open source file.\n";

open (TARGET, ">", $ARGV[1]) or die "Can't open target file.\n";

  1. Burn first line with lables and then go through the input file
  2. line by line

<SOURCE>;

while ($line = <SOURCE>) {

   #split line up on commas
   @data = split(/,/,$line);
   #pull off username from email (assumes email is the 10th entry)
   $username = $data[10];
   $username =~ s/@.*//;
   
   #print new csv
   #follows lst format.  assumes that student id is first entry, last name
   # is second entry etc.... 
   print TARGET "$data[0],$data[1],$data[2],c,,$data[21],,$data[10],$username\n";

}

close TARGET or die "Can't close target file.\n";