prompt.html

来自「perl教程」· HTML 代码 · 共 138 行

HTML
138
字号
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>ActiveState::Prompt - Interactive questions</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body>

<script>writelinks('__top__',2);</script>
<h1><a>ActiveState::Prompt - Interactive questions</a></h1>
<p><a name="__index__"></a></p>

<!-- INDEX BEGIN -->

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#synopsis">SYNOPSIS</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<li><a href="#bugs">BUGS</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>ActiveState::Prompt - Interactive questions</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
 <span class="keyword">use</span> <span class="variable">ActiveState::prompt</span> <span class="string">qw(prompt yes enter)</span><span class="operator">;</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>The following functions are provided:</p>
<dl>
<dt><strong><a name="item_prompt">prompt( $question )</a></strong>

<dt><strong>prompt( $question, $default )</strong>

<dt><strong>prompt( $question, %opts )</strong>

<dd>
<p>This function will ask a question on the terminal and return the
answer given.  The return value will always be defined.</p>
</dd>
<dd>
<p>Options can be passed in as key/value pairs.  The following options
are recognized:</p>
</dd>
<dd>
<pre>
  default
  trim_space
  must_match
  no_match_msg
  use_default
  silent</pre>
</dd>
<dd>
<p>The <code>default</code> is 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.</p>
</dd>
<dd>
<p>If <code>trim_space</code> is TRUE, then any leading and trailing space in the
anwer is trimmed off and any internal space is collapsed to a single
space.</p>
</dd>
<dd>
<p>The <code>must_match</code> value 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.</p>
</dd>
<dd>
<p>The <code>no_match_msg</code> is printed if the given answer does not validate
as specified in <code>must_match</code>.</p>
</dd>
<dd>
<p>If <code>use_default</code> is TRUE, then no answer is read from the terminal
and the default is returned (or &quot;&quot; if there is no default).  The
<code>use_default</code> is by default TRUE if the program is not running on a
terminal or if the PERL_MM_USE_DEFAULT environment variable is TRUE.</p>
</dd>
<dd>
<p>The <code>silent</code> option works like <code>use_default</code> but it also prevent the
prompt text from being printed.  This forces <a href="#item_prompt"><code>prompt()</code></a> to return the default
without actually prompting.</p>
</dd>
</li>
<dt><strong><a name="item_yes">yes( $question )</a></strong>

<dt><strong>yes( $question, $default )</strong>

<dd>
<p>Will use the prompt function to ask a question and then return a TRUE
value if the answer was &quot;yes&quot; or &quot;y&quot;.</p>
</dd>
<dd>
<p>The $default can either be a string like &quot;yes&quot;, &quot;y&quot;, &quot;no&quot; or &quot;n&quot;, or a
boolean value in which case &quot;yes&quot; will be the default if TRUE and &quot;no&quot;
otherwise.  If no $default is given it defaults to &quot;no&quot;.</p>
</dd>
</li>
<dt><strong><a name="item_enter"><code>enter()</code></a></strong>

<dd>
<p>Ask the use to press some key before the function returns.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="bugs">BUGS</a></h1>
<p>None.</p>

</body>

</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?