CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Switch case problem

 



techtween
Novice

May 3, 2011, 12:36 AM

Post #1 of 4 (772 views)
Switch case problem Can't Post

Hi all,

i am a beginner.. Have a problem with switch case in perl.

I have some five choices to be displayed. Even after execution, an option should display as would you like to continue. if yes is specified the choices menu should again be displayed... how to do... if you can specify the structure of program, i can start with it.. Kindly help me..


(This post was edited by techtween on May 3, 2011, 2:34 AM)


rovf
Veteran

May 3, 2011, 12:59 AM

Post #2 of 4 (765 views)
Re: [techtween] Switch case problem [In reply to] Can't Post

Perl/Tk?

See

http://www.perl.com/pub/1999/10/perltk/

for an overview what it is about, and

http://www.perltk.org/

for the complete resources.


FishMonger
Veteran / Moderator

May 3, 2011, 5:56 AM

Post #3 of 4 (740 views)
Re: [techtween] Switch case problem [In reply to] Can't Post

Create an infinite loop in which you execute your main code and break out of it when the user wants to quit.

Put your menu code in a subroutine and call that sub as needed.


BillKSmith
Veteran

May 3, 2011, 6:00 AM

Post #4 of 4 (739 views)
Re: [techtween] Switch case problem [In reply to] Can't Post

Perl/Tk is an excellent suggestion if GUI menus are required, but GUI projects are probably beyond the ability of a beginner.

For a text only solution:

  • Create a hash which has the options as keys. The value corresponding to each option is a reference to the subroutine which processes that option.


  • Print a message to the user to enter one of the following options.


  • Print the list of options.


  • Input the requested option.


  • Verify that the option exists in the hash.


  • Call the subroutine referenced by the hash value corresponding to that option.


  • After you have this much working, you can put a while loop around it to handle the 'continue' requirement.
    Good Luck,
    Bill

     
     


    Search for (options) Powered by Gossamer Forum v.1.2.0

    Web Applications & Managed Hosting Powered by Gossamer Threads
    Visit our Mailing List Archives