Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Is there a module for handling interactive user inputs?

by johnnywang (Priest)
on Jun 07, 2005 at 05:08 UTC ( #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?
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 ikegami (Pope) on Jun 07, 2005 at 05:25 UTC
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 (Priest) on Jun 08, 2005 at 00:51 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
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? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-09-19 22:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (151 votes), past polls