#!/usr/bin/perl -wn use strict; # @title = qw(A B C D); my ($sum, $full, @g, $warn, $i); my (@class_full) = qw(30 30 30 30 30); chomp; last if /^###.*###/; my ($id, $name, $grade) = split /:/; unless (defined $grade and $id =~ /^\w+\s*$/ and (@g = split " ", $grade) and $#g == $#class_full) { print "$_\n"; next; } # 計算平時成績 $sum = $full = 0.0; for ($i=0; $i<=$#g; ++$i) { next if not $g[$i] =~ /^\d+$/; $sum += $g[$i]; $full += $class_full[$i]; } $sum *= 80.0 / $full; ### 期中預警 $warn = ($sum >= 44) ? "OK" : ($sum >= 30) ? "C" : ($sum >= 27) ? "D" : "E"; ### printf "$id:$name:$grade: %4.1f %2s\n", $sum, $warn;