#!/usr/local/bin/perl

# ssid: name :1:2:3:....:n:
# filename

$homeworkscale = 3 ;
$examscale = 1 ;

sub scale {
   local($i) = $_[0] ;
   if ( $i==0 ) { return $homeworkscale ; }
   if ( ($i%2)==0 ) { return $examscale ; }
   $homeworkscale ;
}


   $fn = "grades" ;

   open(F, $fn) || die "can't open $fn" ;

   $skip = (0==1) ;
   $k = 0 ;
   while ($line=<F>) {
      if ( $line=~ /^#DONE/ ) { $skip = (0==0) ; }
      if ( $skip ) { next; } 

      ($ssn, $name[$k], @marks ) = split( ":", $line ) ;
      $total = 0 ;
      for ( $i=0; $i< $#marks ; $i++ ) {
          $total += $marks[$i] * &scale($i) ;
      }
      $grade[$k] = $k + 100 * $total ;
      $k++ ;
   }

   close(F) ;
   @grade = sort numeric @grade ;
   sub numeric{ -($a <=> $b) ; }

   for ( $i=0; $i<$k; $i++ ) {
      printf (
          "%4d: %s\n",
          $grade[$i]/100,
          $name[$grade[$i]%100]
      ) ;
   }

