0: #!/usr/bin/perl -w
1:
2: # this is just a couple of subroutines
3: # that automate the creation of menus
4: # for CHUI programs.
5: #
6: # it will print a neat looking menu,
7: # chomp the user input and return it.
8: #
9: # it's very simple and really nothing
10: # to show off, but definately something
11: # to share. :)
12:
13:
14: sub ask($) { # takes a question as a parameter
15:
16: print $_[0];
17: my $INput = <STDIN>;
18: chomp $INput;
19: return $INput; # and returns the user input
20: } # end ask() -----------------------------------------
21:
22:
23: sub mkmenu(@) { # takes an array of menu options
24:
25: my $title = shift @_; # first cell is the title
26: my $question = pop @_; # last cell is the question
27:
28: print "\n" x 25, "=" x 80;
29: print " " x (40 - length($title) / 2);
30: print "$title\n", "=" x 80, "\n\n";
31:
32: my $i = 1;
33: foreach $el (@_) {
34: print "\t\t\t$i\t$el\n";
35: $i++;
36: }
37: print "\n", "=" x 80;
38: $i = 1;
39: foreach $el (@_) {
40: print " $i=$el |";
41: $i++;
42: }
43:
44: ask($question);
45: } # end mkmenu() --------------------------------------
46:
47:
48: # the following is a sample of how to use it
49:
50: my @menuItems = ("MainMenu",
51: "Input File", "Output file", "Help", "Options", "Exit",
52: " Choose: ");
53:
54: my $choice = mkmenu(@menuItems);
55: print "Your choice is $choice\n";
56:
57:
58: # the following is the result of the above code
59: #
60: #================================================================================
61: # MainMenu
62: #================================================================================
63: #
64: # 1 Input File
65: # 2 Output file
66: # 3 Help
67: # 4 Options
68: # 5 Exit
69: #
70: #================================================================================
71: # 1=Input File | 2=Output file | 3=Help | 4=Options | 5=Exit | Choose:
72:
73:
In reply to Automate Making Menus by staeryatz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |