%g=("a"=>4, "b"=>3, "c"=> 2, "d"=>1, "f"=>0, "+"=> 1/3 , "-"=> -1/3); while (<>){ chomp; next unless m/^([abcdf])([+-])?$/; $n+=1; $t+= $g{$1}; m/(a\+|f-)/ or $t+=$g{$2};} print($t/$n,"\n");
(takes input in the form of one grade, lower case, per line.)
-resc

Replies are listed 'Best First'.
RE: gpa.pl
by ColonelPanic (Friar) on Aug 23, 2000 at 23:02 UTC
    Here's a better one, maybe. Note: my method of calculating GPA is slightly different. + and - add/sub. .5 instead of 1/3.
    chomp($_=<>);$a=$_;s/([^a-f+-]|e)//ig;s/f//ig;s/a/spit(2);/ig; s/b/print;/ig;s/c/eof;/ig;s/d/}d/ig;s/.\-//ig;$b=$_;$_=$a; s/[^abcdf]//ig;$_=length;$b=length$b;$_=$b/(2*$_);print;
    Update: Hey, the first time I didn't see the big 4...it was just mashed together. Neat. BTW, this can take input from a file or STDIN, formatted in any way or not at all. And it uses the rare spit() function :)