⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cgi.html

📁 perl教程
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<dl>
<dt><strong><a name="item__3acgi"><strong>:cgi</strong></a></strong>

<dd>
<p>Import all CGI-handling methods, such as <strong>param()</strong>, <strong>path_info()</strong>
and the like.</p>
</dd>
</li>
<dt><strong><a name="item__3aform"><strong>:form</strong></a></strong>

<dd>
<p>Import all fill-out form generating methods, such as <strong>textfield()</strong>.</p>
</dd>
</li>
<dt><strong><a name="item__3ahtml2"><strong>:html2</strong></a></strong>

<dd>
<p>Import all methods that generate HTML 2.0 standard elements.</p>
</dd>
</li>
<dt><strong><a name="item__3ahtml3"><strong>:html3</strong></a></strong>

<dd>
<p>Import all methods that generate HTML 3.0 elements (such as
&lt;table&gt;, &lt;super&gt; and &lt;sub&gt;).</p>
</dd>
</li>
<dt><strong><a name="item__3ahtml4"><strong>:html4</strong></a></strong>

<dd>
<p>Import all methods that generate HTML 4 elements (such as
&lt;abbrev&gt;, &lt;acronym&gt; and &lt;thead&gt;).</p>
</dd>
</li>
<dt><strong><a name="item__3anetscape"><strong>:netscape</strong></a></strong>

<dd>
<p>Import all methods that generate Netscape-specific HTML extensions.</p>
</dd>
</li>
<dt><strong><a name="item__3ahtml"><strong>:html</strong></a></strong>

<dd>
<p>Import all HTML-generating shortcuts (i.e. 'html2' + 'html3' +
'netscape')...</p>
</dd>
</li>
<dt><strong><a name="item__3astandard"><strong>:standard</strong></a></strong>

<dd>
<p>Import &quot;standard&quot; features, 'html2', 'html3', 'html4', 'form' and 'cgi'.</p>
</dd>
</li>
<dt><strong><a name="item__3aall"><strong>:all</strong></a></strong>

<dd>
<p>Import all the available methods.  For the full list, see the CGI.pm
code, where the variable %EXPORT_TAGS is defined.</p>
</dd>
</li>
</dl>
<p>If you import a function name that is not part of CGI.pm, the module
will treat it as a new HTML tag and generate the appropriate
subroutine.  You can then use it like any other HTML tag.  This is to
provide for the rapidly-evolving HTML &quot;standard.&quot;  For example, say
Microsoft comes out with a new tag called &lt;gradient&gt; (which causes the
user's desktop to be flooded with a rotating gradient fill until his
machine reboots).  You don't need to wait for a new version of CGI.pm
to start using it immediately:</p>
<pre>
   <span class="keyword">use</span> <span class="variable">CGI</span> <span class="string">qw/:standard :html3 gradient/</span><span class="operator">;</span>
   <span class="keyword">print</span> <span class="variable">gradient</span><span class="operator">(</span><span class="operator">{</span><span class="string">-start</span><span class="operator">=&gt;</span><span class="string">'red'</span><span class="operator">,</span><span class="string">-end</span><span class="operator">=&gt;</span><span class="string">'blue'</span><span class="operator">}</span><span class="operator">);</span>
</pre>
<p>Note that in the interests of execution speed CGI.pm does <strong>not</strong> use
the standard <a href="../lib/Exporter.html">the Exporter manpage</a> syntax for specifying load symbols.  This may
change in the future.</p>
<p>If you import any of the state-maintaining CGI or form-generating
methods, a default CGI object will be created and initialized
automatically the first time you use any of the methods that require
one to be present.  This includes <strong>param()</strong>, <strong>textfield()</strong>,
<strong>submit()</strong> and the like.  (If you need direct access to the CGI
object, you can find it in the global variable <strong>$CGI::Q</strong>).  By
importing CGI.pm methods, you can create visually elegant scripts:</p>
<pre>
   <span class="keyword">use</span> <span class="variable">CGI</span> <span class="string">qw/:standard/</span><span class="operator">;</span>
   <span class="keyword">print</span> 
       <span class="variable">header</span><span class="operator">,</span>
       <span class="variable">start_html</span><span class="operator">(</span><span class="string">'Simple Script'</span><span class="operator">),</span>
       <span class="variable">h1</span><span class="operator">(</span><span class="string">'Simple Script'</span><span class="operator">),</span>
       <span class="variable">start_form</span><span class="operator">,</span>
       <span class="string">"What's your name? "</span><span class="operator">,</span><span class="variable">textfield</span><span class="operator">(</span><span class="string">'name'</span><span class="operator">),</span><span class="variable">p</span><span class="operator">,</span>
       <span class="string">"What's the combination?"</span><span class="operator">,</span>
       <span class="variable">checkbox_group</span><span class="operator">(</span><span class="string">-name</span><span class="operator">=&gt;</span><span class="string">'words'</span><span class="operator">,</span>
                      <span class="string">-values</span><span class="operator">=&gt;</span><span class="operator">[</span><span class="string">'eenie'</span><span class="operator">,</span><span class="string">'meenie'</span><span class="operator">,</span><span class="string">'minie'</span><span class="operator">,</span><span class="string">'moe'</span><span class="operator">]</span><span class="operator">,</span>
                      <span class="string">-defaults</span><span class="operator">=&gt;</span><span class="operator">[</span><span class="string">'eenie'</span><span class="operator">,</span><span class="string">'moe'</span><span class="operator">]</span><span class="operator">),</span><span class="variable">p</span><span class="operator">,</span>
       <span class="string">"What's your favorite color?"</span><span class="operator">,</span>
       <span class="variable">popup_menu</span><span class="operator">(</span><span class="string">-name</span><span class="operator">=&gt;</span><span class="string">'color'</span><span class="operator">,</span>
                  <span class="string">-values</span><span class="operator">=&gt;</span><span class="operator">[</span><span class="string">'red'</span><span class="operator">,</span><span class="string">'green'</span><span class="operator">,</span><span class="string">'blue'</span><span class="operator">,</span><span class="string">'chartreuse'</span><span class="operator">]</span><span class="operator">),</span><span class="variable">p</span><span class="operator">,</span>
       <span class="variable">submit</span><span class="operator">,</span>
       <span class="variable">end_form</span><span class="operator">,</span>
       <span class="variable">hr</span><span class="operator">,</span><span class="string">"\n"</span><span class="operator">;</span>
</pre>
<pre>
    <span class="keyword">if</span> <span class="operator">(</span><span class="variable">param</span><span class="operator">)</span> <span class="operator">{</span>
       <span class="keyword">print</span> 
           <span class="string">"Your name is "</span><span class="operator">,</span><span class="variable">em</span><span class="operator">(</span><span class="variable">param</span><span class="operator">(</span><span class="string">'name'</span><span class="operator">)),</span><span class="variable">p</span><span class="operator">,</span>
           <span class="string">"The keywords are: "</span><span class="operator">,</span><span class="variable">em</span><span class="operator">(</span><span class="keyword">join</span><span class="operator">(</span><span class="string">", "</span><span class="operator">,</span><span class="variable">param</span><span class="operator">(</span><span class="string">'words'</span><span class="operator">))),</span><span class="variable">p</span><span class="operator">,</span>
           <span class="string">"Your favorite color is "</span><span class="operator">,</span><span class="variable">em</span><span class="operator">(</span><span class="variable">param</span><span class="operator">(</span><span class="string">'color'</span><span class="operator">)),</span><span class="string">".\n"</span><span class="operator">;</span>
    <span class="operator">}</span>
    <span class="keyword">print</span> <span class="variable">end_html</span><span class="operator">;</span>
</pre>
<p>
</p>
<h2><a name="pragmas">PRAGMAS</a></h2>
<p>In addition to the function sets, there are a number of pragmas that
you can import.  Pragmas, which are always preceded by a hyphen,
change the way that CGI.pm functions in various ways.  Pragmas,
function sets, and individual functions can all be imported in the
same <a href="../lib/Pod/perlfunc.html#item_use"><code>use()</code></a> line.  For example, the following use statement imports the
standard set of functions and enables debugging mode (pragma
-debug):</p>
<pre>
   <span class="keyword">use</span> <span class="variable">CGI</span> <span class="string">qw/:standard -debug/</span><span class="operator">;</span>
</pre>
<p>The current list of pragmas is as follows:</p>
<dl>
<dt><strong><a name="item__2dany">-any</a></strong>

<dd>
<p>When you <em>use CGI -any</em>, then any method that the query object
doesn't recognize will be interpreted as a new HTML tag.  This allows
you to support the next <em>ad hoc</em> Netscape or Microsoft HTML
extension.  This lets you go wild with new and unsupported tags:</p>
</dd>
<dd>
<pre>
   <span class="keyword">use</span> <span class="variable">CGI</span> <span class="string">qw(-any)</span><span class="operator">;</span>
   <span class="variable">$q</span><span class="operator">=</span><span class="variable">new</span> <span class="variable">CGI</span><span class="operator">;</span>
   <span class="keyword">print</span> <span class="variable">$q</span><span class="operator">-&gt;</span><span class="variable">gradient</span><span class="operator">(</span><span class="operator">{</span><span class="string">speed</span><span class="operator">=&gt;</span><span class="string">'fast'</span><span class="operator">,</span><span class="string">start</span><span class="operator">=&gt;</span><span class="string">'red'</span><span class="operator">,</span><span class="string">end</span><span class="operator">=&gt;</span><span class="string">'blue'</span><span class="operator">}</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<p>Since using &lt;cite&gt;any&lt;/cite&gt; causes any mistyped method name
to be interpreted as an HTML tag, use it with care or not at
all.</p>
</dd>
</li>
<dt><strong><a name="item__2dcompile">-compile</a></strong>

<dd>
<p>This causes the indicated autoloaded methods to be compiled up front,
rather than deferred to later.  This is useful for scripts that run
for an extended period of time under FastCGI or mod_perl, and for
those destined to be crunched by Malcom Beattie's Perl compiler.  Use
it in conjunction with the methods or method families you plan to use.</p>
</dd>
<dd>
<pre>
   <span class="keyword">use</span> <span class="variable">CGI</span> <span class="string">qw(-compile :standard :html3)</span><span class="operator">;</span>
</pre>
</dd>
<dd>
<p>o

⌨️ 快捷键说明

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