Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Is there a module for handling interactive user inputs?

by johnnywang (Priest)
on Jun 07, 2005 at 05:08 UTC ( [id://464153]=perlquestion: print w/replies, xml ) Need Help??

johnnywang has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm in need of a commandline script that asks the user a few questions, takes the answers (with validation for some answers), and does something. It's not difficult to write a simple one, but is there an existing module? Thanks.
  • Comment on Is there a module for handling interactive user inputs?

Replies are listed 'Best First'.
Re: Is there a module for handling interactive user inputs?
by ikegami (Patriarch) on Jun 07, 2005 at 05:25 UTC
Re: Is there a module for handling interactive user inputs?
by TheStudent (Scribe) on Jun 07, 2005 at 05:17 UTC
    Take a look at: Shell::Base

    From the doc:

    After writing several REP (Read-Eval-Print) loops in Perl, I found myself wishing for something a little more convenient than starting with:
    while(1) { my $line = <STDIN>; last unless defined $line; chomp $line; if ($line =~ /^...

    TheStudent

Re: Is there a module for handling interactive user inputs?
by TedPride (Priest) on Jun 07, 2005 at 06:54 UTC
    How about something like the following?
    use strict; use warnings; my $word = getInp('Enter a word : ', qr/^[a-z]+$/i); my $anything = getInp('Enter anything : '); sub getInp { print $_[0]; do { $_ = <STDIN>; chomp; } while ($_[1] && $_ !~ $_[1]); return $_; }
    You just pass it your query and a regex and let it worry about doing the validation.
Re: Is there a module for handling interactive user inputs?
by TheDamian (Vicar) on Jun 08, 2005 at 00:51 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://464153]
Approved by kvale
Front-paged by tlm
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-20 03:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found