in reply to conditional statement

There's no point in speeding up something that you do only once or twice (though there's still good reason to make it nicer to read).

If you do many such lookups, just construct an array with the grades and look it up:

# do this once: my @grades = ( ('F' ) x 40, # 0..39 ('E' ) x 10, # 40..49 ('D' ) x 10, # 50..59 ('C' ) x 5, # 60..64 ('C+') x 5, # 65..69 ... ); # do this many times: my $grade = $grades[$ARGV[0]]; print "The student has gotten a $grade grade for the score of $ARGV[0] +.";

Replies are listed 'Best First'.
Re^2: Conditional statement
by Jenda (Abbot) on Apr 25, 2012 at 16:18 UTC

    And in case you did not want to have to count then number of different numbers that get the same grade, you could assign it like this:

    my @grades; @grades[0..39] = ('F') x 50; @grades[40..49] = ('E') x 50; @grades[50..59] = ('D') x 50; @grades[60..64] = ('C') x 50; @grades[65..69] = ('C+') x 50; ...
    You just have to make sure the number at the end of the assignments is higher than the maximum number of scores with the same grade.

    Another option would be this:

    my @grades; $_ = 'F' for @grades[0..39]; $_ = 'E' for @grades[40..49]; $_ = 'D' for @grades[50..59]; $_ = 'C' for @grades[60..64]; $_ = 'C+' for @grades[65..69]; ...

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.