I am searching for a module that I expect should exist, but I'm not finding it. I see things that touch the edge, but don't really do what I'm seeking. Hopefully someone can point me the right way...

I am looking for a module for use with a terminal-based application that allows me to "get input" and provide validation parameters. For example, I'm expecting a module that would let me do something roughly like this:

$results = getInput( -prompt=>"Enter a number between 1 and 10: ", -type=>INTEGER, -LTE=>10, #less than or equal to -GTE=>1, #greater than or equal to -maxTries=>10);
or maybe
@results = getInput( -prompt=>"Pick one or more of the following:\n", -type=>LIST, -list=>["apple", "banana", "carrot"], -allowMultiple, -maxTries=>10);
or maybe even
$results = getInput( -prompt=>"Enter a username: ", -type=>STRING, -minLen=>3, #minimum length -maxLen=>15, #max length -restrictTo=>sub{/[A-Za-z0-9_@.-]+/} # the idea is to be able to pass a regex to validate -maxTries=>10);

I'm expecting the module to prompt the user, get the input, and validate it before returning a result (or results). I wouldn't expect it to cover all possibilities, but if it could cover the most common types of input data, that would be great.

data validators for CGI exist, but this would be more interative - when the user screwed up, they would be asked again.

Does something like this exist?

Thanks! - Paul


In reply to terminal input & data validation by pfaulstich

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.