Hey Monks!
I currently have about 30 scripts that I am trying to build a menu system for, but having a VERY difficult time doing so. Basically, the menu system builds the command and calls each script. Each script works like so: "scriptWrapper.pl -infile File -script Script". The menu needs to define the script and build the infile.
For example, the menu starts at a main menu, from there lets say you choose account menu, that displays and you choose addUser. In the addUser portion you can load an infile and then it gets validated. If a line in the infile is not valid, it takes you to manually edit the option. If you do not have an infile you can manually add users and build an infile. This returns an infile and the script. The problem is, I am unsure really how to do this. Sample code is below:
Main Menu
sub mainMenu {
my ($choice,$notice);
while (1) {
system("clear");
$choice=displayMenu("main",$notice);
if ($choice =~ /a/i) {
accountMenu();
last;
}
elsif ($choice =~ /s/i) {
serverMenu();
last;
}
elsif ($choice =~ /m/i) {
miscMenu();
last;
}
else {
$notice="INVALID OPTION!";
next;
}
}
}
Account Menu
sub accountMenu {
my ($notice,$choice);
while (1) {
$choice=displayMenu("accountMenu",$notice)
if ($choice == 1) {
changePassword();
last;
}
elsif ($choice == 2) {
addAccount();
last;
}
else {
$notice="INVALID OPTION";
}
}
}
addAccount
sub addAccount {
while (1) {
displayMenu("add");
if ($choice == 1) {
my $tempInFile=getInput("PLEASE ENTER FULL PATH TO INPUT F
+ILE > ");
my $csv = Text::CSV->new();
open (CSV, "<$tempInFile") or die "COULD NOT OPEN $tempInF
+ile ($!)\n";
while (<CSV>) {
if ($csv->parse($_)) {
my @columns = $csv->fields();
validateOptions("add","$infile",@columns);
} else {
my $err = $csv->error_input;
print "Failed to parse line: $err";
}
}
close CSV;
last;
}
elsif ($choice == 2) {
manuallyEnterUser("add"," ");
last;
}
elsif ($choice =~ /a/i) {
accountMenu();
}
elsif ($choice =~ /m/i) {
mainMenu();
}
elsif ($choice =~ /e/i) {
exit(0);
}
else {
$notice="INVALID OPTION";
next;
}
}
}
As you can see right now the code is not returning the script or infile, but really at this point I have so many function calls for just one option that I am just completely lost here. Is there a better way to do this? A good module anyone can recommend? Anything??
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.