#!/usr/bin/perl -w # this is just a couple of subroutines # that automate the creation of menus # for CHUI programs. # # it will print a neat looking menu, # chomp the user input and return it. # # it's very simple and really nothing # to show off, but definately something # to share. :) sub ask($) { # takes a question as a parameter print $_[0]; my $INput = ; chomp $INput; return $INput; # and returns the user input } # end ask() ----------------------------------------- sub mkmenu(@) { # takes an array of menu options my $title = shift @_; # first cell is the title my $question = pop @_; # last cell is the question print "\n" x 25, "=" x 80; print " " x (40 - length($title) / 2); print "$title\n", "=" x 80, "\n\n"; my $i = 1; foreach $el (@_) { print "\t\t\t$i\t$el\n"; $i++; } print "\n", "=" x 80; $i = 1; foreach $el (@_) { print " $i=$el |"; $i++; } ask($question); } # end mkmenu() -------------------------------------- # the following is a sample of how to use it my @menuItems = ("MainMenu", "Input File", "Output file", "Help", "Options", "Exit", " Choose: "); my $choice = mkmenu(@menuItems); print "Your choice is $choice\n"; # the following is the result of the above code # #================================================================================ # MainMenu #================================================================================ # # 1 Input File # 2 Output file # 3 Help # 4 Options # 5 Exit # #================================================================================ # 1=Input File | 2=Output file | 3=Help | 4=Options | 5=Exit | Choose: