in reply to Re: Passing input through a hash then displaying results
in thread Passing input through a hash then displaying results

What if he scored 89? That's why the looping is needed ( if you use a hash ).
  • Comment on Re^2: Passing input through a hash then displaying results

Replies are listed 'Best First'.
Re^3: Passing input through a hash then displaying results
by logie17 (Friar) on Jan 23, 2007 at 07:19 UTC
    I would think for such a simple program no need to loop, but just simple if control statements would suffice.
    s;;5776?12321=10609$d=9409:12100$xx;;s;(\d*);push @_,$1;eg;map{print chr(sqrt($_))."\n"} @_;

      Sorry, I meant to say "That's why the looping is needed if you use a hash."

      Of course, you could just do

      sub get_score { my ($score) = @_; return 'A' if $score >= 90; return 'B' if $score >= 80; return 'C' if $score >= 70; return 'D' if $score >= 60; return 'F'; }
      How do I represent the values and keys in a loop or conditional statement?
        How do I represent the values and keys in a loop or conditional statement?

        You gets the keys and values of a hash using keys and values.
        There is various documentation throughout the internet: keys and values.

        I'm not sure if map counts as a loop, but if it does, then this has hash values in a loop and a conditional (or two):

        sub get_grade { my $score = shift; my $grade = 'Ungraded'; $score = 0 unless $score =~ /^\d+$/; map { $grade = $grade_scores{$_} if $score > $_ } sort keys %grade_s +cores; $grade; }

        -=( Graq )=-