http://www.perlmonks.org?node_id=695388

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

What's a good way to structure an interactive text-mode script? That is, one that presents to the user multiple questions, with subsequent questions depending upon answers already given.

Here's the kind of pseudo-code that immediately comes to mind, but which gets unmanageable very quickly:

my $main_choice; while ($main_choice = prompt(...)) { if ($main_choice eq 'task_1') { my $next_choice = prompt(...); if ($next_choice eq 'task_1_a') { #... } elsif ($next_choice eq 'task_1_b') { my $deeper_choice = prompt(); if ($deeper_choice eq 'task_1_b_1') { #... } elsif ($next_choice eq 'task_1_b_2') { #... } else { #... } } elsif ($next_choice eq 'task_1_c') { #... } else { #... } } elsif ($main_choice eq 'task_2') { #... } else { #... } }