Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I am having trouble with this...its gotta be something simple but I just don't seem to be able to put my finger on it. I am very new to programming as well as perl.
here is my code:
use strict; my %commands = ( "command1" => \&sub1, "command2" => \&sub2, "command3" => \&sub3, "command4" => \&sub4, "command5" => \&sub5, "command6" => \&sub6, "exit" => sub { die "Goodbye" } ); while(1){ print "1. command1\n"; print "2. command2\n"; print "3. command3\n"; print "4. command4\n"; print "5. command5\n"; print "6. command6\n"; print "7. exit\n"; print "\n\n"; print "Please choose an option from the menu above: "; chomp(my $commands = <STDIN>); if ($commands{my $string}) { $commands{$string}->(); } else { print "No such command: $string\n"; } }
it keeps printing "No such command" no matter what I type...can't put my finger on it...I left out the subs from the above code because I figured it was irrelivent.
Any help would be great!
2001-04-21 Edit by Corion : Added CODE tags and formatting
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Simple menu..
by jptxs (Curate) on Oct 11, 2000 at 02:37 UTC | |
|
RE: Simple menu..
by chromatic (Archbishop) on Oct 11, 2000 at 02:59 UTC | |
by Anonymous Monk on Oct 11, 2000 at 03:37 UTC | |
by Anonymous Monk on Nov 20, 2003 at 13:03 UTC |