in reply to conditional statement

Another way, which looks a little nicer using Switch statements
use warnings; use strict; use feature "switch"; my $letter; given ($ARGV[0]) { when ([0..39]) { $letter = 'F' ; } when ($_ <= 49) { $letter = 'E' ; } when ($_ <= 59) { $letter = 'D' ; } when ($_ <= 64) { $letter = 'C' ; } when ($_ <= 69) { $letter = 'C+'; } when ($_ <= 74) { $letter = 'B' ; } when ($_ <= 79) { $letter = 'B+'; } when ($_ <= 100) { $letter = 'A' ; } } if ($letter) { print "The student has gotten a $letter grade for the score of $AR +GV[0].\n"; } else { print "Please enter a value between 0 and 100\n"; }

UDPATE: Here is the original question before the owner deleted it:

I started perl a few days ago so are there any ways to make this chunk of code more efficient? The user is supposed to input a score and it'll display something like "The student has gotten a A grade for the score of 100."

#!/usr/bin/perl -w if($ARGV[0] ~~ [0..39]){ print "The student has gotten a F grade for the score of $ARGV[0]. +"; }elsif($ARGV[0] <= 49) { print "The student has gotten a E grade for the score of $ARGV[0]. +"; }elsif($ARGV[0] <= 59) { print "The student has gotten a D grade for the score of $ARGV[0]. +"; }elsif($ARGV[0] <= 64) { print "The student has gotten a C grade for the score of $ARGV[0]. +"; }elsif($ARGV[0] <= 69) { print "The student has gotten a C+ grade for the score of $ARGV[0] +."; }elsif($ARGV[0] <= 74) { print "The student has gotten a B grade for the score of $ARGV[0]. +"; }elsif($ARGV[0] <= 79) { print "The student has gotten a B+ grade for the score of $ARGV[0] +."; }elsif($ARGV[0] <= 100) { print "The student has gotten a A grade for the score of $ARGV[0]. +"; }else { print "Please enter a value between 0 and 100"; }
Thanks in advance. Victor

Replies are listed 'Best First'.
Re^2: Conditional statement
by victorlai (Initiate) on Apr 24, 2012 at 17:57 UTC
    Thanks I appreciate it.