^P It shouldn't be too difficult to handroll this one (update: although now seeing it, I prefer the cdarke solution above actually).

^C something like (untested):

# cls => 1 # option to clear tty screen # opt => [ letter, text, coderef, ... ] # menu choices # to make a code ref assign sub { your-code } to the array element # in this way assign handling code to each choice letter sub GetChoice { my %opt = @_ or die; # using hash-style parameters $opt{ cls } ||= 0 and system 'cls'; my $maxchoice = $#{ $opt{ opt } } - 2; my %coderef = {}; my $done = 0; do { for ( my $choice = 0; $choice <= $maxchoice; $choice += 3 ) { ( ref( $opt{ opt }[ $choice + 2 ] eq 'CODE' ) or die "not a code reference"; $coderef{ $opt{ opt }[ $choice ] } = $opt{ opt }[ $choice + 2 +]; my $text = $opt{ opt }[ $choice + 1 ]; chomp $text; $text .= "\n\n"; print $opt{ opt }[ $choice ] . "\t$text"; } print "Enter option code: "; my $input = <>; if ( $input ~= /^(\w)/ ) { if ( defined( $coderef { $1 } ) ) { $coderef -> { $1 }(); $done = 1; } } unless( $done ) { $opt { cls } && system( 'cls' ); warn "Invalid option code $input"; } } until ( $done ); }
__________________________________________________________________________________

^M Free your mind!

Key to hats: ^I=white ^B=black ^P=yellow ^E=red ^C=green ^M=blue - see Moron's scratchpad for fuller explanation.


In reply to Re: ksh like menu in perl. by Moron
in thread ksh like menu in perl. by shobhit

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.