#!/usr/local/bin/perl
$home="/u/cs/class/cs131/cs131ta";
$col=0;
%columns = (		#last,first,sid,seas,lecture,hw1,hw2,p1,mid,hw3,hw4,p2,final
  sid   => $col++,	#can also put number instead of using $col
  seas  => $col++,
  lname => $col++,
  fname => $col++,
#  honesty => $col++,
#  lecture => $col++,
  hw1pa   => $col++,
  hw1wa   => $col++,
  hw2pa   => $col++,
  hw2wa   => $col++,
  hw3pa   => $col++,
  hw3wa   => $col++,
  hw4pa   => $col++,
  hw4wa   => $col++,
  hw5pa   => $col++,
  hw5wa   => $col++,
  hw6pa   => $col++,
  hw6wa   => $col++,
  mid   => $col++,
  final => $col++,
#  late  => $col++,      #used their one day LAW grace period
);
$columns{law}=$columns{late};
undef $col;

sub convert_col {
  return ($columns{lc $_[0]} or $_[0]);
}

$grade_file="$home/grades/grades.csv";

sub readgrades {
  open (GRADES, "$grade_file") or die "Can't read grades\n $!";
  @grades=<GRADES>;
  close (GRADES);
}

sub writegrades {
  open (GRADES, ">$grade_file") or die "Can't write grades\n $!";
  print GRADES @grades;
  close (GRADES);
}

#need the below one as file must end with 'true' value
1
