in reply to Simple menu..
The way it's phrased in your menu, I'd expect to type '1' and have sub1() execute.
Unfortunately, I'd have to type 'command1' to hit the correct hash key.
If my assumption is incorrect, please respond with the data you've entered.
Update: I completely missed this the first time. What you *really* want is:
You were assigning the input to $commands, but not doing anything with it. You also declared $string within the hash check, assuring that it was undefined.chomp(my $string = <STDIN> ); if ($commands{$string}) { $commands{$string}->(); } else { print "No such command: $string\n"; }
You did get the chomp part correct, which was the problem I had when I first tried something like this, though.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: Simple menu..
by Anonymous Monk on Oct 11, 2000 at 03:37 UTC | |
by Anonymous Monk on Nov 20, 2003 at 13:03 UTC |