in reply to problem with input command
print "Insert your command:"; $input = <STDIN>; if ($input eq "help") { # do something } elsif ($input eq "other command") { # do something else }
Of course, if your commands are allowed to receive parameters,
print "Insert your command:"; $input = <STDIN>; if ($input =~ /^help\s+(.*)/) { # do something } elsif ($input =~ /^other command\s+(.*)/) { # do something else }
The parameters (the full string following the original command and any spaces after it) will be store in the special variable $1
You can even have a final condition for the case in which the inserted command was not valid:
else { print "'$input' is not a valid command. Type help for a full list of + commands.\n"; }
|
|---|