Perl - Help with Menu script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl - Help with Menu script
# 1  
Old 11-08-2011
Perl - Help with Menu script

Hi,

I'm trying to wrtie a menu perl script which will allow users to connect to different servers from a management server without having to know the long server name.

I have written the below code, but when I execute it I manage to get through the first 2 menus but it doesn't exit once connected to the server (I thought the Last command would cause the Loop to exit).

Any ideas?



Code:
#!/usr/bin/perl
 
do
 
{
 
   system('clear');
   print "Please Select a Server";
   print <<MENU_END;
 
    [1].................BOB
    [2].................BERT
    [3].................HARRY
    [4].................LEE
    [5].................BILL
    [6].................ANDY
    [Q].................Quit
MENU_END
 
    chomp($choice = <>);
 
    RESPONSE1:
    {
     $choice = '1' && do {
        system('clear');
        print "Which Data Centre: ";
                           chomp($dc = <>);
                           `./goto BOB$dc`; sleep 2; last RESPONSE1; };
     $choice = '2' && do {
        system('clear');
        print "Which Data Centre: ";
                           chomp($dc = <>);
                           `./goto BERT$dc`; sleep 2; last RESPONSE1; };
     $choice = '3' && do {
        system('clear');
        print "Which Data Centre: ";
                           chomp($dc = <>);
                           `./goto HARRY$dc`; sleep 2; last RESPONSE1; };
     $choice = '4' && do {
        system('clear');
        print "Which Data Centre: ";
                           chomp($dc = <>);
                           `./goto LEE$dc`; sleep 2; last RESPONSE1; };
     $choice = '5' && do {
        system('clear');
        print "Which Data Centre: ";
                           chomp($dc = <>);
                           `./goto BILL$dc`; sleep 2; last RESPONSE1; };
     $choice = '6' && do {
        system('clear');
        print "Which Data Centre: ";
                           chomp($dc = <>);
                           `./goto ANDY$dc`; sleep 2; last RESPONSE1; };
 
     };
} while $choice ne 'Q';

# 2  
Old 11-12-2011
What are you intending with this...
Code:
`./goto ANDY$dc`

??
# 3  
Old 11-13-2011
Quote:
Originally Posted by chris01010
...
I have written the below code, but when I execute it I manage to get through the first 2 menus but it doesn't exit once connected to the server (I thought the Last command would cause the Loop to exit).
Any ideas?
Code:
#!/usr/bin/perl
 
do
 
{
 
   system('clear');
   print "Please Select a Server";
   print <<MENU_END;
 
    [1].................BOB
    [2].................BERT
    [3].................HARRY
    [4].................LEE
    [5].................BILL
    [6].................ANDY
    [Q].................Quit
MENU_END
 
    chomp($choice = <>);
 
    RESPONSE1:
    {
     $choice = '1' && do {
        system('clear');
        print "Which Data Centre: ";
                           chomp($dc = <>);
                           `./goto BOB$dc`; sleep 2; last RESPONSE1; };
     $choice = '2' && do {
        system('clear');
        print "Which Data Centre: ";
                           chomp($dc = <>);
                           `./goto BERT$dc`; sleep 2; last RESPONSE1; };
     $choice = '3' && do {
        system('clear');
        print "Which Data Centre: ";
                           chomp($dc = <>);
                           `./goto HARRY$dc`; sleep 2; last RESPONSE1; };
     $choice = '4' && do {
        system('clear');
        print "Which Data Centre: ";
                           chomp($dc = <>);
                           `./goto LEE$dc`; sleep 2; last RESPONSE1; };
     $choice = '5' && do {
        system('clear');
        print "Which Data Centre: ";
                           chomp($dc = <>);
                           `./goto BILL$dc`; sleep 2; last RESPONSE1; };
     $choice = '6' && do {
        system('clear');
        print "Which Data Centre: ";
                           chomp($dc = <>);
                           `./goto ANDY$dc`; sleep 2; last RESPONSE1; };
 
     };
} while $choice ne 'Q';

Change the "=" operator in the following lines to the "eq" operator:

Code:
24:     $choice = '1' && do {
29:     $choice = '2' && do {
34:     $choice = '3' && do {
39:     $choice = '4' && do {
44:     $choice = '5' && do {
49:     $choice = '6' && do {

The numbers on the left are the line numbers in the Perl program.
You want to compare $choice to the strings '1', '2', '3', ... and so you should use "eq". The "=" operator assigns the strings to $choice.

About your belief - yes, the "last" command in the following form:

Code:
last LABEL

will immediately exit the loop specified by "LABEL". And, in your program, the control will go the first executable statement inside the topmost "do" loop.
That is, the "last RESPONSE1" will cause the control to go to the topmost "system('clear')" statement at line # 7.

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Gnome 3.28.3 menu item dissapears under the system menu

I installed CentOS 8 with Gnome 3.28.2 and I noticed that the "switch user" menu item disappeared from under the system menu of Gnome classic (Both X11 & Wayland). I checked google and this problem seems to have a history going back several releases of Gnome. Unfortunately, I never found a... (1 Reply)
Discussion started by: bodisha
1 Replies

2. Shell Programming and Scripting

Script to call a menu script and redirect each option to a text file

Hello, I want to design a script that will call an existing menu script and select options one by one and redirict the out put to a file. For example;- In the script MENU.sh there are 10 options i want to design a script MENU2.sh that will select option 2 3 4 6 7 10 and redirict the output... (4 Replies)
Discussion started by: spradha
4 Replies

3. Shell Programming and Scripting

How to select a particular field from a drop-down menu in a webpage using perl script?

Hi Team, I have a requirement to login into URL using username and password , then I have to select a "particular name" from drop-down menu and then Read the values user records etc.... using perl. Is it possible to do in perl script ? (OR) Can you please let me know which scripting... (1 Reply)
Discussion started by: latika
1 Replies

4. Shell Programming and Scripting

Need help in create menu with 3 sub menu using the case command

hi all i am a newbie to this is there any examples on creating a main menu with 3 sub menu main menu -> option a , b and c a menu -> option 1 ,2 and 3 b menu -> option 1 ,2 c menu -> option 1 ,2 i am getting headache as my code kept getting unexpected EOF ---------- Post... (0 Replies)
Discussion started by: chercm
0 Replies

5. Shell Programming and Scripting

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... (1 Reply)
Discussion started by: jahburmski
1 Replies

6. Shell Programming and Scripting

Menu in Menu script issue

Problem: I am trying to create a menu in a menu script and I am running into an issue with the calculator portion of the script. I am first presented with the ==Options Menu== which all 5 options working correctly. Now comes the fun part. I select option 1 which takes me to my ==Calculator... (1 Reply)
Discussion started by: iDdraig
1 Replies

7. Shell Programming and Scripting

Menu Script

So, I need help writing a Menu script in UNIX. First how can I use letters for the options instead of numbers? Also, is there any templates out on the web I can use? (2 Replies)
Discussion started by: Gboy
2 Replies

8. Shell Programming and Scripting

Need help with script for menu

I'm working on a script for a basic menu with four options. The first option for the menu asks a user to put in anyone's user name and is supposed to display the user's home directory. If a user does not enter a name, then their own home directory should be displayed. The second menu option is... (0 Replies)
Discussion started by: sinjin
0 Replies

9. Shell Programming and Scripting

Menu script

It's me again :) I would like to create a script that will display a 'Main Menu' which will link to other scripts in the same directory. Is it possible to have a scrolling menu and pretty colours for this? :) (9 Replies)
Discussion started by: Ypnos
9 Replies
Login or Register to Ask a Question