#########################
# PERL TIPS #
#########################
=begin comment
1 WYSWYG strings (split across multiple lines)
2 Single brackets dont process symbols (\n), just shows them
3 Variable symbols for DECLARATION
**for interpretation use $ for all***
Scalar(simple) '$'
Array '@'
Hash/value pairs '%'
4 print doesnt need ()
=cut
#########################
# Grade Calculator #
#########################
use Switch; #cpanm package
print ("\n\tEnter your score: ");
#Global variable
$score = <STDIN>; #get user input
chomp $score; #remove newline char
print "\n Your grade: ",gradeCalc(),"\n";
# Converts numeric score to letter grade
#
sub gradeCalc{
my $grade; #local variable
switch ($score){
case [90..100]{ $grade= "A"; }
case [80..89] { $grade= "B"; }
case [70..79] { $grade= "C"; }
case [60..69] { $grade= "D"; }
else { $grade= "F"; }
}
return $grade;
}
<STDIN>;
Comments