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


in reply to STDIN method?

In the spirit of TMTOWTDI:

#!/bin/perl use strict; use warnings; my $choice = 0; my @choices = (undef, "Turkey", "Steak", "Chicken", "Ground Beef", "Ma +shed Potatoes", "Apple Turnover", "Cherry Pie", "Giblet Stuffing", "G +oat Liver", "Goat Cheese", "Head Cheese", "Cheeseburger"); my $num = scalar @choices - 1; print "Choices is $num\n"; while ($choice < 1 or $choice > $num) { print "\nChoose 1 of the $num options:\n"; foreach (1 .. $num) { print "$_ $choices[$_]\n"; } print "\nChoice: "; $choice = <STDIN>; $choice += 0; } print "\nYou choose $choices[$choice].\n";

Updated: Added more options to better match what vivekvp is going to do with it.
Also, this is probably not the best way to do it. It was fun to write though. :)