Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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.";

Comment on Re: Ksh
Download Code

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 musing on the Monastery: (4)
As of 2015-11-28 23:41 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (746 votes), past polls