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