sub_chick has asked for the wisdom of the Perl Monks concerning the following question:
With this i wondered if it was possible to take the test($guess < $num) and write up a hash instead to look something like %guess = ($guess < $num) => "Too Low!\n";$count++,while () { print "Pick a number between 1 and $top: "; chomp($guess = <>); if ($guess == 0 || $guess eq '0'){ print "Not a suitable number.\n";} elsif ($guess < $num) { print "Too Low!\n";$count++;} elsif ($guess > $num) { print "Too high!\n"; $count++;} else { print "\a\aW00t W00t! You got it!\n"; $count++;last;} }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Having an expression as a hash key
by japhy (Canon) on Dec 03, 2005 at 21:36 UTC | |
by pKai (Priest) on Dec 03, 2005 at 23:38 UTC | |
by sub_chick (Hermit) on Dec 04, 2005 at 02:32 UTC | |
by McDarren (Abbot) on Dec 04, 2005 at 08:39 UTC | |
by sub_chick (Hermit) on Dec 04, 2005 at 13:35 UTC |