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

📄 day4_1.html

📁 《Perl CGI 6天入门》
💻 HTML
字号:
<html>
<!-- #BeginTemplate "/Templates/backend.dwt" -->

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">

<!--

a:link {  color: blue; text-decoration: none}

a:visited {  color: purple; text-decoration: none}

a:hover {  color: #CC0033; text-decoration: underline}

.smallfont {  font-family: "宋体"; font-size: 9pt; line-height: 12pt}

-->

</style>
<!-- #BeginEditable "doctitle" -->
<title>CGI入门教程</title>
<!-- #EndEditable -->
</head>

<body topmargin="1" leftmargin="2">

<p><!-- #BeginEditable "content" --></p>

<p><tt><span class="smallfont"><b>CGI入门教程<br>
</b><br>
<font color="#FF0000">第一页</font> email子过程<br>
<font color="#FF0000">第二页</font> <a href="day4_2.html">写文件</a><br>
<font color="#FF0000">第三页</font> <a href="day4_3.html">建立log文件</a></span></tt></p>

<p><tt><span class="smallfont">[<a href="day1_1.html">第1天</a>][<a href="day2_1.html">第2天</a>][<a
href="day3_1.html">第3天</a>][第4天][<a href="day5_1.html">第5天</a>][<a
href="day6_1.html">第6天</a>][<a href="../perl.htm">返回</a>]</span></tt></p>

<p><tt><span class="smallfont"> </span></tt></p>

<p><tt><span class="smallfont"><b>第一页:email子过程</b></span></tt></p>

<p><tt><span class="smallfont">#*****************BEGIN BODY************* </span></tt></p>

<p><tt><span class="smallfont">print &quot;&lt;h1&gt;Thank you for filling out the 
form&lt;/h1&gt;&quot;; </span></tt></p>

<p><tt><span class="smallfont">$firstname = $value[0]; <br>
$lastname = $value[1]; <br>
$email = $value[2]; <br>
&nbsp; <br>
print &quot;Your first name is $firstname&lt;BR&gt;&quot;; <br>
print &quot;Your last name is $lastname&lt;BR&gt;&quot;; <br>
print &quot;Your e-mail is $email&lt;BR&gt;&quot;; </span></tt></p>

<p><span class="smallfont"><b><tt>$to = $email;</tt></b> <br>
<b><tt>$from = &quot;clinton\@whouse.gov&quot;;</tt></b> <br>
<b><tt>$sub = &quot;subject of my first e-mail&quot;;</tt></b> <br>
<b><tt>$body = &quot;The form was filled out by $firstname $lastname</tt></b> <br>
<b><tt>Thank you goes on another line.&quot;;</tt></b> </span></p>

<p><span class="smallfont"><b><tt>&amp;email($to,$from,$sub,$body);</tt></b> <br>
&nbsp; <br>
#***************END BODY****************** <br>
</span></p>

<hr WIDTH="100%">

<p><tt><span class="smallfont">在上面的例子中,我在程序的BODY后面增加了7行。你需要拷贝这些行到test2.cgi的BODY中。有两种方式:</span></tt>

<ul>
  <li><tt><span class="smallfont">在PC上的文本编辑器中进行拷贝和粘贴,然后用FTP重新上传,这时不必重新运行chmod。</span></tt></li>
  <li><tt><span class="smallfont">可以在Unix提示符下运行Emacs或Pico,对文件进行修改,然后保存和退出。</span></tt></li>
</ul>

<p><tt><span class="smallfont">这时你可以再试试form。要在testform.htm页面中输入你自己的邮件地址。当你提交这个form时,显示结果与以前一样。但如果你在几秒种后查看你的e-mail,你会看到一封来自President 
Clinton的消息。</span></tt></p>

<p><tt><span class="smallfont">让我们看看这些行:</span></tt></p>

<p><tt><span class="smallfont">$to = $email; </span></tt></p>

<p><tt><span class="smallfont">- 拷贝变量$email中的内容到变量$to中。</span></tt></p>

<p><tt><span class="smallfont">$from = &quot;clinton\@whouse.gov&quot;; </span></tt></p>

<p><tt><span class="smallfont">- 设置变量$form为clinton@whouse.gov。反斜线(\)称为escape 
character。@符号在Perl中有特殊意义,表示一个数组,这时,如果我们不想引用数组,而只用@符号本身,需要在前面加一个&quot;\&quot;。</span></tt></p>

<p><tt><span class="smallfont">例如,如果我敲入下面这行:<br>
$amount = &quot;He owes me $20.00&quot;; <br>
将得到一个错误,因为Perl将试图访问一个称为$20.00的变量。我们可以这样写:<br>
$amount = &quot;He owes me \$20.00&quot;; </span></tt></p>

<p><tt><span class="smallfont">$sub = &quot;subject of my first e-mail&quot;; <br>
这行很直接。</span></tt></p>

<p><tt><span class="smallfont">$body = &quot;The form was filled out by $firstname 
$lastname Thank you goes on another line.&quot;; </span></tt></p>

<p><tt><span class="smallfont">这只是一个命令 - Perl命令总以分号结束。返回的字符是赋给$body的字符串中的另一个字符。这很方便,因为可以敲入引号,然后象在字处理器中一样敲入多行文本,然后用引号结束。最后,象其它语句一样敲入引号。</span></tt></p>

<p><tt><span class="smallfont">也可以象这样而得到相同的结果:</span></tt></p>

<p><tt><span class="smallfont">$body = &quot;The form was filled out by $firstname 
$lastname \n Thank you goes on another line.&quot;; </span></tt></p>

<p><tt><span class="smallfont">\n为换行符 - 当双引号中包含\n时,把它翻译成回车符。这对email也起作用 
- 它是用Ascii,而不是HTML写的。注意HTML不在意源代码是在一行还是在多行。如果想在HTML中加入一行,需要插入一个&lt;BR&gt;或&lt;P&gt;标记符。</span></tt></p>

<p><tt><span class="smallfont">&amp;email($to,$from,$sub,$body); </span></tt></p>

<p><tt><span class="smallfont">email子过程在下面的readparse子过程中定义。它被配置成很好用,只需简单地敲入<br>
&amp;email( addressee , reply-to, subject, message body) </span></tt></p>

<p><tt><span class="smallfont">例子中也可以这样传递参数:</span></tt></p>

<p><tt><span class="smallfont">&amp;email($email,&quot;clinton\@whouse.gov&quot;,&quot;subject 
of my first e-mail&quot;,&quot;This is line 1 \nThis is line 2&quot;); </span></tt></p>

<p><tt><span class="smallfont">但是我认为分别赋值对于程序的编辑和阅读更容易。<a
href="day4_2.html">&gt;&gt;</a><br>
</span></tt></p>
</body>
<!-- #EndTemplate -->
</html>

⌨️ 快捷键说明

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