Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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 taking refuge in the Monastery: (7)
As of 2024-09-13 15:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (21 votes). Check out past polls.

    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.