in reply to Having an expression as a hash key
You could also do this as an array:my %messages = ( -1 => "too low", 0 => "just right", 1 => "too high", ); while (...) { print $messages{ $guess <=> $answer }, "\n"; }
although I'd guess several monks here might take offense to that approach.my @messages = ( "just right", "too high", "too low", ); print $messages[$guess <=> $answer];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Having an expression as a hash key
by pKai (Priest) on Dec 03, 2005 at 23:38 UTC | |
|
Re^2: Having an expression as a hash key
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 |