Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Ksh

by sauoq (Abbot)
on Aug 01, 2002 at 21:11 UTC ( [id://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. ;-)
-sauoq
"My two cents aren't worth a dime.";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-20 00:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found