Ppeoc has asked for the wisdom of the Perl Monks concerning the following question:
Enter option to be parsed 1. Fiction 2. History 3. Religion 10. Non fiction
So once the user enters the number 2, Book 2 will get selected and bunch of other options will be displayed as follows
Selected Book 2. Options are as follow 1. World History 2. American History 3. Oriental History 10. Indian History
Each option is nested differently with different levels. The plan is to use a switch statement on the returned $_ to display options for the next level. How do I navigate to a different part of the program and display options according to the genre selected. Thanks!
use strict; use warnings; use Switch; my $level1; print "Select options: \n 1 Fiction \n 2 History \n 3 Religion \n"; my $no = getIP('Enter a digit : ', /^\d/); switch ($no) { case 1 { $level1 = ?? } case 2 { $level1 = ?? } case 3 { $level1 = ?? } else { $level1= ?? } } print $level1; sub getIP { print $_[0]; do { $_ = <STDIN>; chomp; } while ($_[1] && $_ !~ $_[1]); return $_; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Best way to handle interactive user input?
by kcott (Archbishop) on Nov 26, 2015 at 10:27 UTC | |
by Ppeoc (Beadle) on Nov 26, 2015 at 11:17 UTC | |
|
Re: Best way to handle interactive user input?
by Discipulus (Canon) on Nov 26, 2015 at 08:13 UTC | |
by Ppeoc (Beadle) on Nov 26, 2015 at 08:30 UTC | |
by Ppeoc (Beadle) on Nov 26, 2015 at 08:23 UTC | |
by Discipulus (Canon) on Nov 26, 2015 at 08:30 UTC | |
|
Re: Best way to handle interactive user input?
by Jenda (Abbot) on Nov 26, 2015 at 23:22 UTC | |
|
Re: Best way to handle interactive user input?
by Anonymous Monk on Nov 26, 2015 at 08:01 UTC |