in reply to Re: Re: Re: Re: Getopt::Long
in thread Getopt::Long
Do you really think a large list of if/else statements is the most efficent way to do things?if ($command eq "add") { .... } elseif ($command eq "view") { .... } elseif ($command eq "something") { .... } elseif ( ... ) { .... } elseif ( ... ) { .... } elseif ( ... ) { .... } elseif ( ... ) { .... } elseif ( ... ) { .... } elseif ( ... ) { .... . . . . }
Then you can invoke a command for a menu:%menus = ( 'first' => { 'add' => '&add', 'view' => '&view', 'a' => '\$menus{first}{add}', 'v' => '\$menus{first}{view}', }, 'second' => { 'delete' => '&delete', 'print' => '&print', }, );
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.$menus{first}{$_} if exists $menus{first}{$_}; or print "Command not found.\n" if not exists $menus{first}{$_};
|
|---|