Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: Passing input through a hash then displaying results

by logie17 (Friar)
on Jan 23, 2007 at 07:19 UTC ( [id://596041]=note: print w/replies, xml ) Need Help??


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

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"} @_;
  • Comment on Re^3: Passing input through a hash then displaying results

Replies are listed 'Best First'.
Re^4: Passing input through a hash then displaying results
by ikegami (Patriarch) on Jan 23, 2007 at 07:24 UTC

    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'; }
Re^4: Passing input through a hash then displaying results
by brayshakes (Acolyte) on Jan 23, 2007 at 07:42 UTC
    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 )=-

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://596041]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-19 11:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found