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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Switch case problem



May 3, 2011, 12:36 AM

Post #1 of 4 (776 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)


May 3, 2011, 12:59 AM

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



for an overview what it is about, and

for the complete resources.

Veteran / Moderator

May 3, 2011, 5:56 AM

Post #3 of 4 (744 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.


May 3, 2011, 6:00 AM

Post #4 of 4 (743 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,


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

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