Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: STDIN method?

by Mr. Muskrat (Canon)
on Oct 17, 2002 at 21:38 UTC ( [id://206159]=note: print w/replies, xml ) Need Help??


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. :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://206159]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-06-17 16:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.