?? day4_1.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 "<h1>Thank you for filling out the
form</h1>"; </span></tt></p>
<p><tt><span class="smallfont">$firstname = $value[0]; <br>
$lastname = $value[1]; <br>
$email = $value[2]; <br>
<br>
print "Your first name is $firstname<BR>"; <br>
print "Your last name is $lastname<BR>"; <br>
print "Your e-mail is $email<BR>"; </span></tt></p>
<p><span class="smallfont"><b><tt>$to = $email;</tt></b> <br>
<b><tt>$from = "clinton\@whouse.gov";</tt></b> <br>
<b><tt>$sub = "subject of my first e-mail";</tt></b> <br>
<b><tt>$body = "The form was filled out by $firstname $lastname</tt></b> <br>
<b><tt>Thank you goes on another line.";</tt></b> </span></p>
<p><span class="smallfont"><b><tt>&email($to,$from,$sub,$body);</tt></b> <br>
<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 = "clinton\@whouse.gov"; </span></tt></p>
<p><tt><span class="smallfont">- 設置變量$form為clinton@whouse.gov。反斜線(\)稱為escape
character。@符號在Perl中有特殊意義,表示一個數組,這時,如果我們不想引用數組,而只用@符號本身,需要在前面加一個"\"。</span></tt></p>
<p><tt><span class="smallfont">例如,如果我敲入下面這行:<br>
$amount = "He owes me $20.00"; <br>
將得到一個錯誤,因為Perl將試圖訪問一個稱為$20.00的變量。我們可以這樣寫:<br>
$amount = "He owes me \$20.00"; </span></tt></p>
<p><tt><span class="smallfont">$sub = "subject of my first e-mail"; <br>
這行很直接。</span></tt></p>
<p><tt><span class="smallfont">$body = "The form was filled out by $firstname
$lastname Thank you goes on another line."; </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 = "The form was filled out by $firstname
$lastname \n Thank you goes on another line."; </span></tt></p>
<p><tt><span class="smallfont">\n為換行符 - 當雙引號中包含\n時,把它翻譯成回車符。這對email也起作用
- 它是用Ascii,而不是HTML寫的。注意HTML不在意源代碼是在一行還是在多行。如果想在HTML中加入一行,需要插入一個<BR>或<P>標記符。</span></tt></p>
<p><tt><span class="smallfont">&email($to,$from,$sub,$body); </span></tt></p>
<p><tt><span class="smallfont">email子過程在下面的readparse子過程中定義。它被配置成很好用,只需簡單地敲入<br>
&email( addressee , reply-to, subject, message body) </span></tt></p>
<p><tt><span class="smallfont">例子中也可以這樣傳遞參數:</span></tt></p>
<p><tt><span class="smallfont">&email($email,"clinton\@whouse.gov","subject
of my first e-mail","This is line 1 \nThis is line 2"); </span></tt></p>
<p><tt><span class="smallfont">但是我認為分別賦值對于程序的編輯和閱讀更容易。<a
href="day4_2.html">>></a><br>
</span></tt></p>
</body>
<!-- #EndTemplate -->
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -