Menu: Difference between revisions

Content added Content deleted
(→‎{{header|Perl 6}}: Add Perl 6 example)
Line 862: Line 862:


print "You chose: $a\n";</lang>
print "You chose: $a\n";</lang>

=={{header|Perl 6}}==
<lang perl6>sub menu ( $prompt, @items ) {
return '' unless @items.elems;
my $selection = '';
repeat until $selection ~~ /^ \d+ $/ && @items[--$selection].so
{
my $i = 1;
say " {$i++}) $_" for @items;
$selection = prompt $prompt;
}
return @items[$selection];
}

my @choices = ('fee fie', 'huff and puff', 'mirror mirror', 'tick tock');
my $prompt = 'Enter the number corresponding to your selection: ';

my $answer = menu( $prompt, [] );
say "You chose: $answer" if $answer.chars;

$answer = menu( $prompt, @choices );
say "You chose: $answer" if $answer.chars;</lang>


=={{header|PL/I}}==
=={{header|PL/I}}==