Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Ksh

by sauoq (Abbot)
on Aug 01, 2002 at 21:11 UTC ( #186937=note: print w/replies, xml ) Need Help??

in reply to Ksh style select menus in perl

Something like the following might help get you started. Call it with the prompt and list of words. It'll return either undef or the word selected in scalar context. In list context it will also return the reply entered by the user. (To preserve the $REPLY functionality of the ksh builtin.) It preserves my ksh's interpretation of input which allows trailing characters after the number.

sub ksh_like_select { my $prompt = shift; my @words = @_; my $retval; my $reply; do { my $i = 1; print STDERR $i++, ")\t$_\n" for @words; print $prompt; $reply = <STDIN>; } while ($reply eq ''); if ($reply =~ /^(\d+)/ and $1 > 0 and $1 <= @words) { $retval = $words[$1-1]; } wantarray() ? ($retval,$reply) : $retval; }
Caution: Don't rename it "select" before using it. ;-)
"My two cents aren't worth a dime.";

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2016-10-22 06:44 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (292 votes). Check out past polls.