Perl simple text menu with options


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl simple text menu with options
# 1  
Old 12-11-2011
Perl simple text menu with options

Hopefully I'm in the right place. Im new to the forums and linux!

I'm looking to add a menu to my perl hangman game i have created. The menu will use user input for the desired option and then perform the operation indicated. I would like something along the lines of:

Welcome to Hangman
If you would like to continue press 1 (calls module to run hangman game)
Press 0 to exit (exits the script)

prior to writing the hangman script i did not declare which version to use so im assuming its running an older version.

Similarly i need another menu that has 3 options that open up to another menu.

For instance:

1. system commands
2. edit commands > opens menu with 3 options that just print something
3. admin commands > opens menu with 3 options that each print something
4. network commands > opens menu wtih 3 options that each print something
5. games
6. exit

some sort of input validation would be nice to.

Any and all help would be greatly appreciated. thank you.
# 2  
Old 12-12-2011
The following code demonstrates a basic menu by using <STDIN> for reading input.

Code:
#!/usr/bin/perl

use strict;
use warnings;
use Switch;

my $input = '';

while ($input ne '6')
{
    clear_screen();

    print "1. system commands\n".
          "2. edit commands\n". 
          "3. admin commands\n". 
          "4. network commands\n". 
          "5. games\n".
          "6. exit\n";

    print "Enter your choice: ";
    $input = <STDIN>;
    chomp($input);

    switch ($input)
    {
        case '2'
        {
            $input = '';

            while ($input ne '4')
            {
                clear_screen();

                print "1. edit > option 1\n".
                      "2. edit > option 1\n".
                      "3. edit > option 3\n".
                      "4. return to main menu\n";

                print "Enter your choice: ";
                $input = <STDIN>;
                chomp($input);
            }

            $input = '';
        }

    }
}

exit(0);

sub clear_screen
{
    system("clear");
}

These 3 Users Gave Thanks to MacMonster For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to include menu based options in Shell script?

Hi Friends, I have a menu based tool which requires input/option to proceed further. How to make a shell script ? eg: menu looks like Get_data.sh to continue (y/n) : Here I need to key in "y" to proceed. I want to prepare a script which should consider option y. (5 Replies)
Discussion started by: suresh3566
5 Replies

2. Shell Programming and Scripting

Automate the menu options using shell script

I have a menu option which will look as follows Select a menu option 1.change password 2.login as root user 3.show system version 4.quit Select> 1 please enter the new password: unix reenter the new password: unix press any key to enter (then displays again the menu options to enter the... (4 Replies)
Discussion started by: shivakumar6g
4 Replies

3. Shell Programming and Scripting

Menu with sub-menu options

Hi! I have created on script which is working fine with menu options and with a sub-menu. I want to enhance it by using sub-options under menu options. Like. option 1) will give the list only. option 1.1) should give the option to user to choose one file, whose content user wanna see. ... (3 Replies)
Discussion started by: sukhdip
3 Replies

4. Windows & DOS: Issues & Discussions

Windows Advanced Options Menu

I dual boot between Windows XP and Linux Mint. I am trying to get the Windows Advanced Options Menu to show up. Normally you would press f8 to make this happen when your computer is booting. With a dual boot it makes it way more complicated. If you press f8 when your computer first starts it does... (3 Replies)
Discussion started by: cokedude
3 Replies

5. Homework & Coursework Questions

Menu Driven Shell Script which accepts1 to 5 options

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 1) Write a Menu Driven Shell Script which accepts1 to 5 options and performs the following actions for... (1 Reply)
Discussion started by: vaghya
1 Replies

6. Shell Programming and Scripting

help with scripting a simple menu

Hi there. I'm trying to teach myself UNIX but the book I bought is a bit confusing. I'm trying out this exercise and I think I'm on the right track, but I'd appreciate any suggestions on how to improve what I have so far. Also, I'm not clear on how to use the read command to utilize the user's... (3 Replies)
Discussion started by: Jsmith
3 Replies

7. Shell Programming and Scripting

menu.lst, boot options?

Hi all, I would like to have some details on menu.lst!! the reason is ,if i am trying to add my own boot option where do i need to add it? is it in menu.lst only or elsewere(am referring to unix os) because i tried adding a unique boot option and it was not reflected when the system booted?... (8 Replies)
Discussion started by: wrapster
8 Replies

8. UNIX for Dummies Questions & Answers

Help needed with menu options

I'm programming a menu for an intro to unix class and am hung up on 2 required options. One has to exit from unix. The other has to get a command prompt by using one of the menu choices, then return to the menu via CTRL-D. below is my code #!/bin/ksh #Jimmy's happy menu mesg y msg="ON"... (2 Replies)
Discussion started by: sanitywonko
2 Replies

9. UNIX for Dummies Questions & Answers

changing root menu options on Redaht

Hello all, I would like to change the options on the root menu when I use the middle button on a three mouse buttom setting. I can append to the menu but, I seem to be unable to find the lisp code for pop-root-menu. Does anyone know how to change this? THANKS ALL (3 Replies)
Discussion started by: larry
3 Replies
Login or Register to Ask a Question