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

📄 cgiprogramming.mht

📁 Perl 编程技巧大全。适合初学者阅读。
💻 MHT
📖 第 1 页 / 共 5 页
字号:
#-----------------------------
</FONT></PRE></FONT></TD></TR></TBODY></TABLE></DIV>
<DIV class=3DSECT2>
<H2 class=3DSECT2><A name=3DAEN1025>Executing Commands Without Shell=20
Escapes</A></H2>
<TABLE width=3D"100%" bgColor=3D#2f4f4f border=3D0>
  <TBODY>
  <TR>
    <TD><PRE class=3DSCREEN><FONT color=3D#f5deb3 size=3D+1><FONT =
color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#98fb98>system</FONT><FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>"command $input =
</FONT><FONT color=3D#cdad00>@files</FONT><FONT =
color=3D#00cd00>"</FONT><FONT color=3D#00ffff>);</FONT>            <FONT =
color=3D#bebebe># UNSAFE
#-----------------------------
</FONT><FONT color=3D#98fb98>system</FONT><FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>"command"</FONT>, $input, =
<FONT color=3D#cdad00>@files</FONT><FONT color=3D#00ffff>);</FONT>       =
   <FONT color=3D#bebebe># safer
#-----------------------------
</FONT><FONT color=3D#ff7f50>chomp</FONT><FONT =
color=3D#00ffff>(</FONT>$now =3D <FONT =
color=3D#00cd00>`date`</FONT><FONT color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#cdad00>@output</FONT> =3D <FONT =
color=3D#00cd00>`grep $input </FONT><FONT =
color=3D#cdad00>@files</FONT><FONT color=3D#00cd00>`</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#ffa500>die</FONT> <FONT color=3D#00cd00>"cannot =
fork: $!"</FONT> <FONT color=3D#ffa500>unless</FONT> <FONT =
color=3D#ff7f50>defined</FONT> <FONT color=3D#00ffff>(</FONT>$pid =3D =
<FONT color=3D#98fb98>open</FONT><FONT color=3D#00ffff>(</FONT>SAFE_KID, =
<FONT color=3D#00cd00>"|-"</FONT><FONT color=3D#00ffff>));</FONT>
<FONT color=3D#ffa500>if</FONT> <FONT color=3D#00ffff>(</FONT>$pid =
=3D=3D <FONT color=3D#cdcd00>0</FONT><FONT color=3D#00ffff>)</FONT> =
<FONT color=3D#00ffff>{</FONT>
    <FONT color=3D#ffa500>exec</FONT><FONT color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>'grep'</FONT>, $input, <FONT =
color=3D#cdad00>@files</FONT><FONT color=3D#00ffff>)</FONT> <FONT =
color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> <FONT =
color=3D#00cd00>"can't exec grep: $!"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#00ffff>}</FONT> <FONT color=3D#ffa500>else</FONT> <FONT =
color=3D#00ffff>{</FONT>
    <FONT color=3D#cdad00>@output</FONT> =3D &lt;SAFE_KID&gt;<FONT =
color=3D#00ffff>;</FONT>
    <FONT color=3D#98fb98>close</FONT> SAFE_KID<FONT =
color=3D#00ffff>;</FONT>                 <FONT color=3D#bebebe># $? =
contains status
</FONT><FONT color=3D#00ffff>}</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#98fb98>open</FONT><FONT =
color=3D#00ffff>(</FONT>KID_TO_READ, <FONT color=3D#00cd00>"$program =
</FONT><FONT color=3D#cdad00>@options</FONT><FONT color=3D#00cd00> =
</FONT><FONT color=3D#cdad00>@args</FONT><FONT color=3D#00cd00> =
|"</FONT><FONT color=3D#00ffff>);</FONT>    <FONT color=3D#bebebe># =
UNSAFE
#-----------------------------
# add error processing as above
</FONT><FONT color=3D#ffa500>die</FONT> <FONT color=3D#00cd00>"cannot =
fork: $!"</FONT> <FONT color=3D#ffa500>unless</FONT> <FONT =
color=3D#ff7f50>defined</FONT><FONT color=3D#00ffff>(</FONT>$pid =3D =
<FONT color=3D#98fb98>open</FONT><FONT =
color=3D#00ffff>(</FONT>KID_TO_READ, <FONT =
color=3D#00cd00>"-|"</FONT><FONT color=3D#00ffff>));</FONT>

<FONT color=3D#ffa500>if</FONT> <FONT color=3D#00ffff>(</FONT>$pid<FONT =
color=3D#00ffff>)</FONT> <FONT color=3D#00ffff>{</FONT>   <FONT =
color=3D#bebebe># parent
</FONT>   <FONT color=3D#ffa500>while</FONT> <FONT =
color=3D#00ffff>(</FONT>&lt;KID_TO_READ&gt;<FONT =
color=3D#00ffff>)</FONT> <FONT color=3D#00ffff>{</FONT>
       <FONT color=3D#bebebe># do something interesting
</FONT>   <FONT color=3D#00ffff>}</FONT>
   <FONT color=3D#98fb98>close</FONT><FONT =
color=3D#00ffff>(</FONT>KID_TO_READ<FONT color=3D#00ffff>)</FONT>        =
       <FONT color=3D#98fb98>or</FONT> <FONT color=3D#98fb98>warn</FONT> =
<FONT color=3D#00cd00>"kid exited $?"</FONT><FONT =
color=3D#00ffff>;</FONT>

<FONT color=3D#00ffff>}</FONT> <FONT color=3D#ffa500>else</FONT> <FONT =
color=3D#00ffff>{</FONT>      <FONT color=3D#bebebe># child
</FONT>   <FONT color=3D#bebebe># reconfigure, then
</FONT>   <FONT color=3D#ffa500>exec</FONT><FONT =
color=3D#00ffff>(</FONT>$program, <FONT color=3D#cdad00>@options</FONT>, =
<FONT color=3D#cdad00>@args</FONT><FONT color=3D#00ffff>)</FONT>  <FONT =
color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> <FONT =
color=3D#00cd00>"can't exec program: $!"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#00ffff>}</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#98fb98>open</FONT><FONT =
color=3D#00ffff>(</FONT>KID_TO_WRITE, <FONT color=3D#00cd00>"|$program =
$options </FONT><FONT color=3D#cdad00>@args</FONT><FONT =
color=3D#00cd00>"</FONT><FONT color=3D#00ffff>);</FONT>   <FONT =
color=3D#bebebe># UNSAFE
#-----------------------------
</FONT>$pid =3D <FONT color=3D#98fb98>open</FONT><FONT =
color=3D#00ffff>(</FONT>KID_TO_WRITE, <FONT =
color=3D#00cd00>"|-"</FONT><FONT color=3D#00ffff>);</FONT>
<FONT color=3D#ffa500>die</FONT> <FONT color=3D#00cd00>"cannot fork: =
$!"</FONT> <FONT color=3D#ffa500>unless</FONT> <FONT =
color=3D#ff7f50>defined</FONT><FONT color=3D#00ffff>(</FONT>$pid =3D =
<FONT color=3D#98fb98>open</FONT><FONT =
color=3D#00ffff>(</FONT>KID_TO_WRITE, <FONT =
color=3D#00cd00>"|-"</FONT><FONT color=3D#00ffff>));</FONT>
<FONT color=3D#cdcd00>$SIG</FONT><FONT color=3D#00ffff>{</FONT><FONT =
color=3D#00cd00>ALRM</FONT><FONT color=3D#00ffff>}</FONT> =3D <FONT =
color=3D#ffa500>sub</FONT> <FONT color=3D#00ffff>{</FONT> <FONT =
color=3D#ffa500>die</FONT> <FONT color=3D#00cd00>"whoops, $program pipe =
broke"</FONT> <FONT color=3D#00ffff>};</FONT>

<FONT color=3D#ffa500>if</FONT> <FONT color=3D#00ffff>(</FONT>$pid<FONT =
color=3D#00ffff>)</FONT> <FONT color=3D#00ffff>{</FONT>  <FONT =
color=3D#bebebe># parent
</FONT>   <FONT color=3D#ffa500>for</FONT> <FONT =
color=3D#00ffff>(</FONT><FONT color=3D#cdad00>@data</FONT><FONT =
color=3D#00ffff>)</FONT> <FONT color=3D#00ffff>{</FONT> <FONT =
color=3D#ff7f50>print</FONT> KID_TO_WRITE $_ <FONT =
color=3D#00ffff>}</FONT>
   <FONT color=3D#98fb98>close</FONT><FONT =
color=3D#00ffff>(</FONT>KID_TO_WRITE<FONT color=3D#00ffff>)</FONT>       =
       <FONT color=3D#98fb98>or</FONT> <FONT color=3D#98fb98>warn</FONT> =
<FONT color=3D#00cd00>"kid exited $?"</FONT><FONT =
color=3D#00ffff>;</FONT>

<FONT color=3D#00ffff>}</FONT> <FONT color=3D#ffa500>else</FONT> <FONT =
color=3D#00ffff>{</FONT>     <FONT color=3D#bebebe># child
</FONT>   <FONT color=3D#bebebe># reconfigure, then
</FONT>   <FONT color=3D#ffa500>exec</FONT><FONT =
color=3D#00ffff>(</FONT>$program, <FONT color=3D#cdad00>@options</FONT>, =
<FONT color=3D#cdad00>@args</FONT><FONT color=3D#00ffff>)</FONT>  <FONT =
color=3D#98fb98>or</FONT> <FONT color=3D#ffa500>die</FONT> <FONT =
color=3D#00cd00>"can't exec program: $!"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#00ffff>}</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT></PRE></FONT></TD></TR></TBODY></TABLE></DIV>
<DIV class=3DSECT2>
<H2 class=3DSECT2><A name=3DAEN1028>Formatting Lists and Tables with =
HTML=20
Shortcuts</A></H2>
<TABLE width=3D"100%" bgColor=3D#2f4f4f border=3D0>
  <TBODY>
  <TR>
    <TD><PRE class=3DSCREEN><FONT color=3D#f5deb3 size=3D+1><FONT =
color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#ff7f50>print</FONT> ol<FONT =
color=3D#00ffff>(</FONT> li<FONT color=3D#00ffff>([</FONT> <FONT =
color=3D#ff7f50>qw</FONT><FONT color=3D#00ffff>(</FONT>red blue =
green<FONT color=3D#00ffff>)])</FONT> <FONT color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe># &lt;OL&gt;&lt;LI&gt;red&lt;/LI&gt; =
&lt;LI&gt;blue&lt;/LI&gt; &lt;LI&gt;green&lt;/LI&gt;&lt;/OL&gt;
</FONT>
<FONT color=3D#cdad00>@names</FONT> =3D <FONT =
color=3D#ff7f50>qw</FONT><FONT color=3D#00ffff>(</FONT>Larry Moe =
Curly<FONT color=3D#00ffff>);</FONT>
<FONT color=3D#ff7f50>print</FONT> ul<FONT color=3D#00ffff>(</FONT> =
li<FONT color=3D#00ffff>({</FONT> <FONT color=3D#00cd00>-TYPE</FONT> =
=3D&gt; <FONT color=3D#00cd00>"disc"</FONT> <FONT =
color=3D#00ffff>}</FONT>, \<FONT color=3D#cdad00>@names</FONT><FONT =
color=3D#00ffff>)</FONT> <FONT color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe># &lt;UL&gt;&lt;LI =
TYPE=3D"disc"&gt;Larry&lt;/LI&gt; &lt;LI TYPE=3D"disc"&gt;Moe&lt;/LI&gt;
#
#     &lt;LI TYPE=3D"disc"&gt;Curly&lt;/LI&gt;&lt;/UL&gt;
#-----------------------------
</FONT><FONT color=3D#ff7f50>print</FONT> li<FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>"alpha"</FONT><FONT =
color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe>#     &lt;LI&gt;alpha&lt;/LI&gt;
</FONT>
<FONT color=3D#ff7f50>print</FONT> li<FONT color=3D#00ffff>(</FONT> =
<FONT color=3D#00ffff>[</FONT> <FONT color=3D#00cd00>"alpha"</FONT>, =
<FONT color=3D#00cd00>"omega"</FONT><FONT color=3D#00ffff>]</FONT> <FONT =
color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe>#     &lt;LI&gt;alpha&lt;/LI&gt; =
&lt;LI&gt;omega&lt;/LI&gt;
#-----------------------------
</FONT><FONT color=3D#ffa500>use</FONT> <FONT color=3D#b2dfee>CGI</FONT> =
<FONT color=3D#ff7f50>qw</FONT><FONT color=3D#00ffff>(</FONT>:standard =
:html3<FONT color=3D#00ffff>);</FONT>

<FONT color=3D#cdcd00>%hash</FONT> =3D <FONT color=3D#00ffff>(</FONT>
    <FONT color=3D#00cd00>"Wisconsin"</FONT>  =3D&gt; <FONT =
color=3D#00ffff>[</FONT> <FONT color=3D#00cd00>"Superior"</FONT>, <FONT =
color=3D#00cd00>"Lake Geneva"</FONT>, <FONT =
color=3D#00cd00>"Madison"</FONT> <FONT color=3D#00ffff>]</FONT>,
    <FONT color=3D#00cd00>"Colorado"</FONT>   =3D&gt; <FONT =
color=3D#00ffff>[</FONT> <FONT color=3D#00cd00>"Denver"</FONT>, <FONT =
color=3D#00cd00>"Fort Collins"</FONT>, <FONT =
color=3D#00cd00>"Boulder"</FONT> <FONT color=3D#00ffff>]</FONT>,
    <FONT color=3D#00cd00>"Texas"</FONT>      =3D&gt; <FONT =
color=3D#00ffff>[</FONT> <FONT color=3D#00cd00>"Plano"</FONT>, <FONT =
color=3D#00cd00>"Austin"</FONT>, <FONT color=3D#00cd00>"Fort =
Stockton"</FONT> <FONT color=3D#00ffff>]</FONT>,
    <FONT color=3D#00cd00>"California"</FONT> =3D&gt; <FONT =
color=3D#00ffff>[</FONT> <FONT color=3D#00cd00>"Sebastopol"</FONT>, =
<FONT color=3D#00cd00>"Santa Rosa"</FONT>, <FONT =
color=3D#00cd00>"Berkeley"</FONT> <FONT color=3D#00ffff>]</FONT>,
<FONT color=3D#00ffff>);</FONT>

$\ =3D <FONT color=3D#00cd00>"\n"</FONT><FONT color=3D#00ffff>;</FONT>

<FONT color=3D#ff7f50>print</FONT> <FONT color=3D#00cd00>"&lt;TABLE&gt; =
&lt;CAPTION&gt;Cities I Have Known&lt;/CAPTION&gt;"</FONT><FONT =
color=3D#00ffff>;</FONT>
<FONT color=3D#ff7f50>print</FONT> Tr<FONT color=3D#00ffff>(</FONT>th =
<FONT color=3D#00ffff>[</FONT><FONT color=3D#ff7f50>qw</FONT><FONT =
color=3D#00ffff>(</FONT>State Cities<FONT color=3D#00ffff>)]);</FONT>
<FONT color=3D#ffa500>for</FONT> <FONT color=3D#9ac0cd>$k</FONT> <FONT =
color=3D#00ffff>(</FONT><FONT color=3D#ff7f50>sort</FONT> <FONT =
color=3D#ff7f50>keys</FONT> <FONT color=3D#cdcd00>%hash</FONT><FONT =
color=3D#00ffff>)</FONT> <FONT color=3D#00ffff>{</FONT>
    <FONT color=3D#ff7f50>print</FONT> Tr<FONT =
color=3D#00ffff>(</FONT>th<FONT color=3D#00ffff>(</FONT>$k<FONT =
color=3D#00ffff>)</FONT>, td<FONT color=3D#00ffff>(</FONT> <FONT =
color=3D#00ffff>[</FONT> <FONT color=3D#ff7f50>sort</FONT> @<FONT =
color=3D#00ffff>{</FONT><FONT color=3D#cdcd00>$hash</FONT><FONT =
color=3D#00ffff>{</FONT>$k<FONT color=3D#00ffff>}}</FONT> <FONT =
color=3D#00ffff>]</FONT> <FONT color=3D#00ffff>));</FONT>
<FONT color=3D#00ffff>}</FONT>
<FONT color=3D#ff7f50>print</FONT> <FONT =
color=3D#00cd00>"&lt;/TABLE&gt;"</FONT><FONT color=3D#00ffff>;</FONT>
<FONT color=3D#bebebe>#-----------------------------
# &lt;TABLE&gt; &lt;CAPTION&gt;Cities I Have Known&lt;/CAPTION&gt;
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
#     &lt;TR&gt;&lt;TH&gt;State&lt;/TH&gt; =
&lt;TH&gt;Cities&lt;/TH&gt;&lt;/TR&gt;
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
#     &lt;TR&gt;&lt;TH&gt;California&lt;/TH&gt; =
&lt;TD&gt;Berkeley&lt;/TD&gt; &lt;TD&gt;Santa =
Rosa&lt;/TD&gt;</FONT><FONT color=3D#43cd80> </FONT><FONT =
color=3D#bebebe>
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
# 	  &lt;TD&gt;Sebastopol&lt;/TD&gt; &lt;/TR&gt;
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
#     &lt;TR&gt;&lt;TH&gt;Colorado&lt;/TH&gt; =
&lt;TD&gt;Boulder&lt;/TD&gt; &lt;TD&gt;Denver&lt;/TD&gt;</FONT><FONT =
color=3D#43cd80> </FONT><FONT color=3D#bebebe>
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
# 	  &lt;TD&gt;Fort Collins&lt;/TD&gt; &lt;/TR&gt;
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
#     &lt;TR&gt;&lt;TH&gt;Texas&lt;/TH&gt; &lt;TD&gt;Austin&lt;/TD&gt; =
&lt;TD&gt;Fort Stockton&lt;/TD&gt;</FONT><FONT color=3D#43cd80> =
</FONT><FONT color=3D#bebebe>
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
# 	  &lt;TD&gt;Plano&lt;/TD&gt;&lt;/TR&gt;
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
#     &lt;TR&gt;&lt;TH&gt;Wisconsin&lt;/TH&gt; &lt;TD&gt;Lake =
Geneva&lt;/TD&gt; &lt;TD&gt;Madison&lt;/TD&gt;</FONT><FONT =
color=3D#43cd80> </FONT><FONT color=3D#bebebe>
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
# 	  &lt;TD&gt;Superior&lt;/TD&gt;&lt;/TR&gt;
#</FONT><FONT color=3D#43cd80> </FONT><FONT color=3D#bebebe>
# &lt;/TABLE&gt;
#-----------------------------
</FONT><FONT color=3D#ff7f50>print</FONT> table
        caption<FONT color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>'Cities I have Known'</FONT><FONT =
color=3D#00ffff>)</FONT>,
        Tr<FONT color=3D#00ffff>(</FONT>th <FONT =
color=3D#00ffff>[</FONT><FONT color=3D#ff7f50>qw</FONT><FONT =
color=3D#00ffff>(</FONT>State Cities<FONT color=3D#00ffff>)])</FONT>,
        <FONT color=3D#ff7f50>map</FONT> <FONT color=3D#00ffff>{</FONT> =
Tr<FONT color=3D#00ffff>(</FONT>th<FONT color=3D#00ffff>(</FONT>$_<FONT =
color=3D#00ffff>)</FONT>, td<FONT color=3D#00ffff>(</FONT> <FONT =
color=3D#00ffff>[</FONT> <FONT color=3D#ff7f50>sort</FONT> @<FONT =

⌨️ 快捷键说明

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