ActiveState::Prompt - Interactive questions
use ActiveState::prompt qw(prompt yes enter);
The following functions are provided:
- prompt( $question )
- prompt( $question, $default )
- prompt( $question, %opts )
This function will ask a question on the terminal and return the answer given. The return value will always be defined.
Options can be passed in as key/value pairs. The following options are recognized:
default trim_space must_match no_match_msg use_default silent
defaultis returned if the user simply press return. The default value is shown in brackets. If no default is provided then no brackets are added to the question.
trim_spaceis TRUE, then any leading and trailing space in the anwer is trimmed off and any internal space is collapsed to a single space.
must_matchvalue is used to validate answers. It can be either a function, array or regular expression. If it is a function, then the function is called with the answer given and should return TRUE if it is to be accepted. If it is an array, then the answer must be one of the values in the array. If it is an regular expression then it must match it.
no_match_msgis printed if the given answer does not validate as specified in
use_defaultis TRUE, then no answer is read from the terminal and the default is returned (or "" if there is no default). The
use_defaultis by default TRUE if the program is not running on a terminal or if the PERL_MM_USE_DEFAULT environment variable is TRUE.
silentoption works like
use_defaultbut it also prevent the prompt text from being printed. This forces prompt() to return the default without actually prompting.
- yes( $question )
- yes( $question, $default )
Will use the prompt function to ask a question and then return a TRUE value if the answer was "yes" or "y".
The $default can either be a string like "yes", "y", "no" or "n", or a boolean value in which case "yes" will be the default if TRUE and "no" otherwise. If no $default is given it defaults to "no".
Ask the use to press some key before the function returns.