victorlai has asked for the wisdom of the Perl Monks concerning the following question:
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."
Thanks in advance. Victor#!/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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Conditional statement
by moritz (Cardinal) on Apr 24, 2012 at 17:26 UTC | |
by Jenda (Abbot) on Apr 25, 2012 at 16:18 UTC | |
|
Re: Conditional statement
by toolic (Bishop) on Apr 24, 2012 at 17:31 UTC | |
by victorlai (Initiate) on Apr 24, 2012 at 17:57 UTC | |
|
Re: conditional statement
by BillKSmith (Monsignor) on Apr 24, 2012 at 19:38 UTC | |
|
Re: conditional statement
by aaron_baugher (Curate) on Apr 25, 2012 at 01:34 UTC | |
|
Re: conditional statement
by locked_user sundialsvc4 (Abbot) on Apr 24, 2012 at 21:54 UTC |